forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_2053.java
More file actions
25 lines (23 loc) · 657 Bytes
/
_2053.java
File metadata and controls
25 lines (23 loc) · 657 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.Map;
public class _2053 {
public static class Solution1 {
public String kthDistinct(String[] arr, int k) {
Map<String, Integer> map = new HashMap<>();
for (String s : arr) {
map.put(s, map.getOrDefault(s, 0) + 1);
}
int count = 0;
for (String s : arr) {
if (map.get(s) == 1) {
count++;
if (k == count) {
return s;
}
}
}
return "";
}
}
}