首页 > 其他 > 详细

【leetcode】73. 矩阵置零

时间:2020-12-12 09:38:29      阅读:27      评论:0      收藏: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;
        }
    }
}
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;
        }
    }
}

 

【leetcode】73. 矩阵置零

原文:https://www.cnblogs.com/ganxiang/p/14123467.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!