zoukankan      html  css  js  c++  java
  • 【leetcode】73. 矩阵置零

    void setZeroes(int** matrix, int matrixSize, int* matrixColSize){
        int* rhash = (int*)calloc(matrixSize, sizeof(int));
        int* chash = (int*)calloc(*matrixColSize, sizeof(int));
        int i, j, k;
        for (i = 0; i < matrixSize; i++){
            for (j = 0; j < *matrixColSize; j++)
            {
                if (matrix[i][j] == 0){
                    rhash[i] = 1;
                    chash[j] = 1;
                }            
            }        
        }
        for (i = 0; i < matrixSize; i++){
            if (rhash[i]==1)
                memset(matrix[i], 0, (*matrixColSize)*sizeof(int));
        }
        for (i = 0; i < *matrixColSize; i++){
            if (chash[i] == 1){
                for (k = 0; k < matrixSize; k++)
                    matrix[k][i] = 0;
            }
        }
    }
    void setZeroes(int** matrix, int matrixSize, int* matrixColSize){
        int* rhash = (int*)calloc(matrixSize, sizeof(int));
        int* chash = (int*)calloc(*matrixColSize, sizeof(int));
        int i, j, k;
        for (i = 0; i < matrixSize; i++){
            for (j = 0; j < *matrixColSize; j++)
            {
                if (matrix[i][j] == 0){
                    rhash[i] = 1;
                    chash[j] = 1;
                }            
            }        
        }
        for (i = 0; i < matrixSize; i++){
            if (rhash[i]==1)
                memset(matrix[i], 0, (*matrixColSize)*sizeof(int));
        }
        for (i = 0; i < *matrixColSize; i++){
            if (chash[i] == 1){
                for (k = 0; k < matrixSize; k++)
                    matrix[k][i] = 0;
            }
        }
    }
  • 相关阅读:
    分层图(了解一下,下一道比较好做)
    图论---The Captain
    数论
    NOIp复习计划
    20201116 Day4 卢卡斯定理
    20201113 Day3 斜率优化
    20201110Day2 分块
    20201030 day50 复习13:逆元、裴蜀定理
    20201030day50 模板全掌握
    20201029 day49 模拟(十八)
  • 原文地址:https://www.cnblogs.com/ganxiang/p/14123467.html
Copyright © 2011-2022 走看看