Skip to content

Commit cc639a3

Browse files
authored
Create 2053-kth-distinct-string-in-an-array.js
1 parent 54d469a commit cc639a3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {string[]} arr
3+
* @param {number} k
4+
* @return {string}
5+
*/
6+
const kthDistinct = function(arr, k) {
7+
let num = 0, hash = {}
8+
9+
for(let str of arr) {
10+
if(hash[str] == null) hash[str] = 0
11+
hash[str]++
12+
}
13+
for(let str of arr) {
14+
if(hash[str] > 1) continue
15+
num++
16+
if(num === k) return str
17+
}
18+
return ''
19+
};

0 commit comments

Comments
 (0)