leetcode 764. Largest Plus Sign | 764. 最大加号标志(Java)
生活随笔
收集整理的這篇文章主要介紹了
leetcode 764. Largest Plus Sign | 764. 最大加号标志(Java)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目
https://leetcode.com/problems/largest-plus-sign/
題解
class Solution {public int orderOfLargestPlusSign(int n, int[][] mines) {boolean[][] arr = new boolean[n][n];for (boolean[] a : arr) {Arrays.fill(a, true);}for (int[] pair : mines) {arr[pair[0]][pair[1]] = false;}int[][] ones = new int[n][n];// count ones leftint count;for (int i = 0; i < n; i++) {count = 0;for (int j = 0; j < n; j++) {if (arr[i][j]) count++;else count = 0;ones[i][j] = count;}}// count ones rightfor (int i = 0; i < n; i++) {count = 0;for (int j = n - 1; j >= 0; j--) {if (arr[i][j]) count++;else count = 0;ones[i][j] = Math.min(ones[i][j], count);}}// count ones upfor (int i = 0; i < n; i++) {count = 0;for (int j = 0; j < n; j++) {if (arr[j][i]) count++;else count = 0;ones[j][i] = Math.min(ones[j][i], count);}}// count ones downfor (int i = 0; i < n; i++) {count = 0;for (int j = n - 1; j >= 0; j--) {if (arr[j][i]) count++;else count = 0;ones[j][i] = Math.min(ones[j][i], count);}}// find global maxint max = Integer.MIN_VALUE;for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {max = Math.max(max, ones[i][j]);}}return max;} }總結
以上是生活随笔為你收集整理的leetcode 764. Largest Plus Sign | 764. 最大加号标志(Java)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: leetcode 164. Maximu
- 下一篇: leetcode 446. Arithm