Skip to content

Commit 696ef67

Browse files
authored
Create 2053. Kth Distinct String in an Array (#547)
2 parents cfa4d43 + 5ca71d6 commit 696ef67

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

2053. Kth Distinct String in an Array

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
string kthDistinct(vector<string>& arr, int k) {
4+
unordered_map<string, int> strFreqMp;
5+
for(auto &str : arr)strFreqMp[str]++;
6+
for(auto &str : arr){
7+
if(strFreqMp[str] == 1)k--;
8+
if(k == 0)return str;
9+
}
10+
return "";
11+
}
12+
};

0 commit comments

Comments
 (0)