Skip to content

Latest commit

 

History

History
32 lines (25 loc) · 866 Bytes

1072. 按列翻转得到最大值等行数.md

File metadata and controls

32 lines (25 loc) · 866 Bytes
  • 哈希表(一开始没想出来怎么写!)
/**
 *
 * 
 * @see https://leetcode-cn.com/problems/flip-columns-for-maximum-number-of-equal-rows/solution/c-jian-dan-ti-jie-by-da-li-wang-21/
 * @param {number[][]} matrix
 * @return {*}  {number}
 */
function maxEqualRowsAfterFlips(matrix: number[][]): number {

    let max: number = 0;

    const map: Map<string, number> = new Map<string, number>();

    for (const rows of matrix) {
        if (rows[0]) {
            rows.forEach((value, index) => rows[index] = 1 - value);
        }
        const key: string = rows.join('');
        const value: number = (map.get(key) || 0) + 1;
        map.set(key, value);
        max = Math.max(max, value);
    }

    return max;
};