异或--to_string的使用
原创
©著作权归作者所有:来自51CTO博客作者wx596330ff6d68f的原创作品,请联系作者获取转载授权,否则将追究法律责任
1072. Flip Columns For Maximum Number of Equal Rows
Given a matrix
consisting of 0s and 1s, we may choose any number of columns in the matrix and flip every cell in that column. Flipping a cell changes the value of that cell from 0 to 1 or from 1 to 0.
Return the maximum number of rows that have all values equal after some number of flips.
Example 1:
Input: [[0,1],[1,1]]
Output: 1
Explanation: After flipping no values, 1 row has all values equal.
Example 2:
Input: [[0,1],[1,0]]
Output: 2
Explanation: After flipping values in the first column, both rows have equal values.
Example 3:
Input: [[0,0,0],[0,0,1],[1,1,0]]
Output: 2
Explanation: After flipping values in the first two columns, the last two rows have equal values.
class Solution {
public:
int maxEqualRowsAfterFlips(vector<vector<int>>& matrix) {
int n = matrix.size();
int m = matrix[0].size();
int Result = 0;
unordered_map<string,int> Map;
for(int i = 0;i < n;i ++){
string tmp;
for(int j = 0;j < m;j ++){
tmp += to_string(matrix[i][0] ^ matrix[i][j]);
}
Map[tmp] ++;
Result = max(Result,Map[tmp]);
}
return Result;
}
};