forked from Nimesh-Srivastava/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0953.cpp
More file actions
32 lines (23 loc) · 718 Bytes
/
0953.cpp
File metadata and controls
32 lines (23 loc) · 718 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
31
32
unordered_map<char, int> m;
class Solution {
public:
static bool cmp(string a, string b) {
int n = min(a.length(), b.length());
for(int i = 0; i < n; i++) {
if(m[a[i]] < m[b[i]])
return true;
else if(m[a[i]] > m[b[i]])
return false;
}
if(a.length() <= b.length())
return true;
return false;
}
bool isAlienSorted(vector<string>& words, string order) {
for(int i = 0; i < order.length(); i++)
m[order[i]] = i;
vector<string> temp = words;
sort(temp.begin(), temp.end(), cmp);
return temp == words;
}
};