-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1657.cpp
More file actions
30 lines (30 loc) · 825 Bytes
/
1657.cpp
File metadata and controls
30 lines (30 loc) · 825 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
26
27
28
29
30
class Solution {
public:
vector<int> getCount(string& s) {
vector<int> cnt(26, 0);
for (auto& c : s) {
cnt[c - 'a']++;
}
vector<int> validNum;
for (auto& num : cnt) {
if (num > 0) validNum.push_back(num);
}
sort(validNum.begin(), validNum.end());
int index = 0;
for (int i = 0; i < 26; ++i) {
if (cnt[i] != 0) {
cnt[i] = validNum[index];
index++;
}
}
return cnt;
}
bool closeStrings(string word1, string word2) {
vector<int> word1Cnt = getCount(word1);
vector<int> word2Cnt = getCount(word2);
for (int i = 0; i < 26; ++i) {
if (word1Cnt[i] != word2Cnt[i]) return false;
}
return true;
}
};