Re: [闲聊] 每日leetcode

楼主: sixB (6B)   2024-05-14 02:41:25
哩扣帮++
原本看这篇想说
比这个在干嘛看不懂==
刚刚想说睡前也来写一下
class Solution {
public:
int matrixScore(vector<vector<int>>& grid) {
int m = grid.size();
int n = grid[0].size();
int res = 0;
for(int i = 0; i < m; i++){
if(grid[i][0] == 0){
for(int &j: grid[i]){
j = !j;
}
}
}
for(int j = 0; j < n; j++){
int cnt = 0;
for(int i = 0; i< m; i++){
cnt += grid[i][j];
}
cnt = max(cnt, m - cnt);
res += cnt * pow(2, n -j -1);
}
return res;
}
};
回来再看看懂了
那个count可以直接加ㄚ
然后那个base好酷 我要偷走了
只剩我还在pow了小朋友呜呜呜呜
※ 引述 《ray90514》 之铭言:
: grid[i][j] == grid[i][0] 可以依照开头的bit与该位的bit得到最终有无翻转的结果
: class Solution {
: public:
: int matrixScore(vector<vector<int>>& grid) {
: int ans = 0;
: int m = grid.size(), n = grid[0].size();
: for(int j = n - 1, base = 1; j >= 0; j
楼主: sixB (6B)   2024-05-14 02:44:00
然后原来for那个要加& ==对不起 我好笨==现在才看懂 在跟前面那个比我先跑一圈翻了 累死睡觉呜呜呜我好笨

Links booklink

Contact Us: admin [ a t ] ucptt.com