Skip to content

Commit 653b92c

Browse files
committed
Time: 6 ms (84.92%), Space: 45.1 MB (5.65%) - LeetHub
1 parent cb648a1 commit 653b92c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public String kthDistinct(String[] arr, int k) {
3+
Map<String, Integer> map = new HashMap<>();
4+
for (String s : arr) {
5+
map.put(s, map.getOrDefault(s, 0) + 1);
6+
}
7+
int index = 0;
8+
for (String s: arr) {
9+
if (map.get(s) == 1) {
10+
index++;
11+
if (index == k) {
12+
return s;
13+
}
14+
}
15+
}
16+
return "";
17+
}
18+
}

0 commit comments

Comments
 (0)