Skip to content

Commit 1047db4

Browse files
Merge pull request #1690 from CodingTestStudy2/이진희
[이진희] Day21
2 parents 80d5753 + 5fd3aa8 commit 1047db4

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
3+
1. 아이디어 : 1개만 존재하는 짝수중 가장 앞쪽의 수 반환. 완전탐색을 통해 미리 각 짝수의 개수를 구하고, 다시 사전식으로 돌려 판단
4+
5+
2. 시간복잡도 : O(2*N)
6+
7+
3. 자료구조/알고리즘 : 완전탐색
8+
9+
*/
10+
11+
class Solution {
12+
public int firstUniqueEven(int[] nums) {
13+
// 정확히 한번 등장하는 사전순으로 가장 빠른 짝수 idx
14+
// 없다면 -1
15+
16+
int[] cnt = new int[101];
17+
18+
for(int i=0; i<nums.length; i++) {
19+
if(nums[i]%2==1) continue;
20+
cnt[nums[i]]++;
21+
}
22+
23+
for(int i=0; i<nums.length; i++) {
24+
if(cnt[nums[i]] == 1) return nums[i];
25+
}
26+
27+
return -1;
28+
}
29+
}

0 commit comments

Comments
 (0)