인프런 커뮤니티 질문&답변
안녕하세요 n2 시간복잡도일 때 문제가 풀리는거 같아서 질문남깁니다.
작성
·
209
2
아래와 같은 코드로 문제를 제출했는데 정답처리를 받았습니다.
해당 코드는 단순히 전부 비교하면서 진행하니까 n2 시간복잡도를 가질꺼라서 안되겠지? 했는데 통과를 해버렸습니다.
break문 때문에 완전n2이 아닐수도 있지만 그래도 시간복잡도는 n2 이지 않나요??
왜 통과과 된건지 알려주시면 감사하겠습니다.
아 그리고 문제는 씨름선수인데 문제 중간 바둑선수라고 문제설명이 되어있습니다. 해당 부분에서 문제 설명 수정이 필요하실 것 같습니다.
import java.util.Scanner;
public class Greedy_1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int result = N;
Man[] mans = new Man[N];
for (int i = 0; i < N; i++) {
int h = sc.nextInt();
int w = sc.nextInt();
mans[i] = new Man(h,w);
}
for (int i = 0; i < mans.length; i++) {
for (int j = 0; j < mans.length; j++) {
if (mans[i].height < mans[j].height && mans[i].weight < mans[j].weight) {
result--;
break;
}
}
}
System.out.println(result);
}
static class Man {
int height;
int weight;
public Man(int height, int weight) {
this.height = height;
this.weight = weight;
}
}





