Easy understanding Java


  • 0
    C
        public int countCornerRectangles(int[][] grid) {
            if(grid == null || grid.length == 0 || grid[0].length == 0) return 0;
            int m = grid.length;
            int n = grid[0].length;
            int res = 0;
            if(m == 1 || n == 1) return 0;
            for(int i = 0; i < m; i ++) {
                for(int j = 0; j < n; j ++) {
                    // every node, we assume it is the left-up point.
                    if (grid[i][j] == 1) {
                        // To find the right-up point
                        for(int k = j+1; k < n; k++) {
                            if (grid[i][k] == 1) {
                                // To find left-bottom point
                                for(int l = i + 1; l < m; l++) {
                                    if (grid[l][j] == 1 && grid[l][k] == 1) {
                                        res ++;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return res;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.