前言
###我做这类文档一个重要的目的还是给正在学习的大家提供方向(例如想要掌握基础用法,该刷哪些题?)我的解析也不会做的非常详细,只会提供思路和一些关键点,力扣上的大佬们的题解质量是非常非常高滴!!!
习题
tip:下面三题就是简单的模拟,所以直接给代码了,也可以去看看力扣大佬们另辟蹊径的题解
1.矩阵置零
题目链接: 73. 矩阵置零 - 力扣(LeetCode)
题面: 
代码:
            
            
              java
              
              
            
          
          class Solution {
    public void setZeroes(int[][] matrix) {
        int n = matrix.length;
        int m = matrix[0].length;
        int[][] flag = new int[n][m];
        for(int i = 0;i<n;i++){
            for(int j = 0;j<m;j++){
                if(matrix[i][j]==0&&flag[i][j]==0){
                    for(int k = 0;k<n;k++){
                        if(matrix[k][j]!=0){
                            flag[k][j] = 1;
                        }
                        matrix[k][j] = 0;
                        
                    }
                    for(int k = 0;k<m;k++){
                        if(matrix[i][k]!=0){
                            flag[i][k] = 1;
                        }
                        matrix[i][k] = 0;
                    }
                }
            }
        }
    }
}2.旋转图像
题目链接: 48. 旋转图像 - 力扣(LeetCode)
题面: 
代码:
            
            
              java
              
              
            
          
          class Solution {
    public void rotate(int[][] matrix) {
        int n = matrix.length;
         int t = n/2;
            int count = 0;
            while(t!=0){
                t--;
             //存第一行
             int[] arr = new int[n];
             for(int i =count;i<n-(count);i++){
                arr[i] = matrix[count][i];
             }
             //左边转到上面
             for(int i = count;i<n-(count);i++){
                matrix[count][i] = matrix[n-1-i][count];
             } 
             //下边转到左边
             for(int i = count;i<n-(count);i++){
                matrix[i][count] = matrix[n-1-count][i];
             }
             //右边转到下面
              for(int i = count;i<n-(count);i++){
                matrix[n-1-count][i] = matrix[n-1-i][n-1-count];
             }
             //上面转到右边
              for(int i = count;i<n-(count);i++){
                matrix[i][n-1-count] = arr[i];
             }
              count++;
            }
    }
}3.搜索二维矩阵II
题目链接: 240. 搜索二维矩阵 II - 力扣(LeetCode)
题面: 
代码:
            
            
              java
              
              
            
          
          class Solution {
    public boolean searchMatrix(int[][] matrix, int target) {
        int n = matrix.length;
        int m = matrix[0].length;
        if(matrix[n-1][m-1]<target)return false;
        int r = 0;
        int low = 0;
        while(r<m&&matrix[0][r]<=target)r++;
        while(low<n&&matrix[low][0]<=target)low++;
        for(int i = 0;i<low;i++){
            for(int j = 0;j<r;j++){
                if(matrix[i][j]==target)return true;
            }
        }
        return false;
    }
}后言
上面是力扣Hot100的矩阵专题,下一篇是其他专题的习题,希望有所帮助,一同进步,共勉!
