Re: [閒聊] 每日leetcode
1504.
我昨天寫正方形也是先看到n < 300
直接開3個loop
class Solution {
public:
int numSubmat(vector<vector<int>>& mat) {
int m = mat.size(), n = mat[0].size();
vector<int> cnt(n, 0);
int res = 0;
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
if(mat[i][j] == 0){
cnt[j] = 0;
continue;
}
cnt[j]++;
int bound = cnt[j];
for(int k = j; k >= 0 and bound > 0; k--){
bound = min(bound, cnt[k]);
res += bound;
}
}
}
return res;
}
};
-----
Sent from JPTT on my iPad
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.135.99.218 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1755798077.A.D25.html
推
08/22 01:43,
3月前
, 1F
08/22 01:43, 1F
推
08/22 01:44,
3月前
, 2F
08/22 01:44, 2F
推
08/22 01:46,
3月前
, 3F
08/22 01:46, 3F
→
08/22 01:54,
3月前
, 4F
08/22 01:54, 4F
推
08/22 02:03,
3月前
, 5F
08/22 02:03, 5F
討論串 (同標題文章)
完整討論串 (本文為第 1506 之 1548 篇):