Re: [閒聊] 每日leetcode

看板Marginalman作者 (6B)時間3月前 (2025/08/22 01:41), 編輯推噓4(401)
留言5則, 5人參與, 3月前最新討論串1506/1548 (看更多)
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
第9行 代數錯了
08/22 01:46, 3F

08/22 01:54, 3月前 , 4F
O(mn)解呢
08/22 01:54, 4F

08/22 02:03, 3月前 , 5F
別卷惹
08/22 02:03, 5F
文章代碼(AID): #1efrezqb (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1efrezqb (Marginalman)