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;
            }
        }
    }
  • 相关阅读:
    一、flink架构模型
    每日看点
    argparse模块用法实例
    Python 牛刀小试
    spark 编程基础
    我想过的100种暴富机会
    hadoop大数据架构
    centOS7 ip 配置
    classNotFound异常的一个原因
    linux上部署java项目
  • 原文地址:https://www.cnblogs.com/ganxiang/p/14123467.html
Copyright © 2011-2022 走看看