-
카테고리
-
세부 분야
알고리즘 · 자료구조
-
해결 여부
미해결
봉우리 문제 컴파일 에러
22.11.17 23:23 작성 조회수 105
0
제 로컬 실행시에는 정답이 나오는데 채점 시 컴파일 에러가 나고있습니다.
뭐가 문제인지 모르겠습니다.
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public static void main(String[] args) {
Main main = new Main();
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
int[][] answers = new int[num + 2][num + 2];
// (1,1) ~ (n,n) 까지 입력됨. - 테두리는 입력되지 않음
for (int row = 1; row <= num; row++) {
for (int col = 1; col <= num; col++) {
answers[row][col] = scanner.nextInt();
}
}
System.out.println(solution(answers));
}
private static int solution(int[][] nums) {
int size = nums.length;
int count = 0;
for (int row = 1; row < size - 1; row++) {
for (int col = 1; col < size - 1; col++) {
int n = nums[row][col];
int up = nums[row - 1][col];
int down = nums[row + 1][col];
int left = nums[row][col - 1];
int right = nums[row][col + 1];
List<Integer> controlGroup = List.of(n, up, down, left, right);
int max = controlGroup.stream()
.max(Comparator.comparing(Integer::intValue))
.get();
boolean isDistinct = controlGroup.stream()
.filter(i -> i == max)
.count() == 1;
if (n == max && isDistinct) {
count++;
}
}
}
return count;
}
답변을 작성해보세요.
0
답변 1