Re: [閒聊] 每日leetcode

看板Marginalman作者 (6B)時間1年前 (2024/11/23 02:54), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1145/1554 (看更多)
1072. bitset 翻一翻 因為要固定size 所以做了個mask 讓超過n的不變 我還是很不習慣直接對數字操作 class Solution { public: int maxEqualRowsAfterFlips(vector<vector<int>>& mat) { unordered_map<bitset<301>, int> mp; int n = mat[0].size(); string m = string(301 - n, '1') + string(n, '0'); bitset<301> mask(m); cout << "M: " << mask << '\n'; for(auto& row: mat){ string bit_s(row.begin(), row.end()); for(char& c: bit_s){ c += '0'; } bitset<301> bs(bit_s); mp[bs | mask]++; bs.flip(); mp[bs | mask]++; } int mx = 1; for(auto& [bs, cnt]: mp){ mx = max(mx, cnt); } return mx; } }; ----- Sent from JPTT on my iPad -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.121.194 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1732301697.A.757.html
文章代碼(AID): #1dGDE1TN (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1dGDE1TN (Marginalman)