diff --git a/1072. Flip Columns For Maximum Number of Equal Rows b/1072. Flip Columns For Maximum Number of Equal Rows new file mode 100644 index 0000000..19a6ca9 --- /dev/null +++ b/1072. Flip Columns For Maximum Number of Equal Rows @@ -0,0 +1,27 @@ +class Solution { +public: + int maxEqualRowsAfterFlips(vector>& matrix) { + unordered_map patternCount; // To store the pattern and its count + + for (const auto& row : matrix) { + string pattern = ""; + + // Generate a pattern string for this row based on the first row + for (int j = 0; j < row.size(); ++j) { + // Compare with the first element in the row to determine if flip is needed + pattern += (row[j] ^ row[0]) ? '1' : '0'; + } + + // Increment the count for this pattern + patternCount[pattern]++; + } + + // Find the maximum count of rows with the same pattern + int maxRows = 0; + for (const auto& entry : patternCount) { + maxRows = max(maxRows, entry.second); + } + + return maxRows; + } +};