작성
·
242
0
Scanner kb = new Scanner(System.in);
int n=kb.nextInt();
int[][] arr=new int[n][n];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
arr[i][j]=kb.nextInt();
}
}
System.out.print(solution(n, arr));
}
public static int solution(int n, int[][] arr) {
int answer = 0;
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
int cur = arr[i][j];
if(j-1 >= 0 && cur < arr[i][j-1]) continue;
if(i+1 < n && cur < arr[i+1][j]) continue;
if(j+1 < n && cur < arr[i][j+1]) continue;
if(i-1 >= 0 && cur < arr[i-1][j]) continue;
answer++;
arr[i][j] = 10;
}
}
return answer;