Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
flip-columns-for-maximum-number-of-equal-rows.cpp 772 Bytes
Copy Edit Raw Blame History
// Time: O(m * n)
// Space: O(m * n)
class Solution {
public:
int maxEqualRowsAfterFlips(vector<vector<int>>& matrix) {
unordered_map<string,int> count;
for (const auto& row : matrix){
++count[encode(row)];
}
using pair_type = decltype(count)::value_type;
return max_element(count.cbegin(), count.cend(),
[] (const pair_type& a,
const pair_type& b) {
return a.second < b.second;
})->second;
}
private:
string encode(const vector<int>& s) {
string result;
for (const auto& c : s) {
result.push_back(c ^ s[0]);
}
return result;
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search