Skip to content

Commit 4247e89

Browse files
Merge pull request #1832 from CodingTestStudy2/이진희
[이진희] Day16
2 parents 87991ee + c098e1b commit 4247e89

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
3+
1. 아이디어 : 모든 k구간을 완전탐색으로 돌며 등장하는 구간 안 중복되지 않은 숫자를 각각 카운트, 가장 큰 수 반환
4+
슬라이딩 윈도우 기법으로 풀려고 했지만, 중복된 숫자가 등장하는 경우를 처리하기가 까다로워 완전탐색으로 품
5+
6+
2. 시간복잡도 : O(N*K+50)
7+
8+
3. 자료구조/알고리즘 : 완전탐색, Set
9+
10+
*/
11+
12+
class Solution {
13+
public int largestInteger(int[] nums, int k) {
14+
int[] cnt = new int[51];
15+
for(int i=0; i<=nums.length-k; i++) {
16+
Set<Integer> set = new HashSet<>();
17+
for(int j=i; j<i+k; j++) {
18+
if(set.contains(nums[j])) continue;
19+
set.add(nums[j]);
20+
cnt[nums[j]]++;
21+
}
22+
}
23+
24+
for(int i=50; i>=0; i--) {
25+
if(cnt[i] == 1) return i;
26+
}
27+
28+
return -1;
29+
}
30+
}

0 commit comments

Comments
 (0)