Skip to content

Commit 49bb98f

Browse files
add 2053
1 parent 07d09a0 commit 49bb98f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2053|[Kth Distinct String in an Array](https://leetcode.com/problems/kth-distinct-string-in-an-array/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2053.java) ||Easy||
1112
|2050|[Parallel Courses III](https://leetcode.com/problems/parallel-courses-iii/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2050.java) ||Hard||
1213
|2048|[Next Greater Numerically Balanced Number](https://leetcode.com/problems/next-greater-numerically-balanced-number/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2048.java) ||Medium||
1314
|2047|[Number of Valid Words in a Sentence](https://leetcode.com/problems/number-of-valid-words-in-a-sentence/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2047.java) ||Easy||
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class _2053 {
7+
public static class Solution1 {
8+
public String kthDistinct(String[] arr, int k) {
9+
Map<String, Integer> map = new HashMap<>();
10+
for (String s : arr) {
11+
map.put(s, map.getOrDefault(s, 0) + 1);
12+
}
13+
int count = 0;
14+
for (String s : arr) {
15+
if (map.get(s) == 1) {
16+
count++;
17+
if (k == count) {
18+
return s;
19+
}
20+
}
21+
}
22+
return "";
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)