Skip to content

Commit b195ec9

Browse files
Merge pull request #1827 from CodingTestStudy2/염혜정
[염혜정] Day15
2 parents ffc5190 + 225ee6e commit b195ec9

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// O(n)...
2+
3+
class Solution {
4+
public int findKthPositive(int[] arr, int k) {
5+
Set<Integer> set = new HashSet<>();
6+
for (int a : arr) set.add(a);
7+
8+
int i = 1;
9+
int cnt = 0;
10+
int result = 0;
11+
while(true) {
12+
if (!set.contains(i)) cnt++;
13+
if (cnt == k) {
14+
result = i;
15+
break;
16+
}
17+
i++;
18+
}
19+
return result;
20+
}
21+
}

0 commit comments

Comments
 (0)