Skip to content

Commit 9bb9462

Browse files
committed
Add 953-955.
1 parent cada034 commit 9bb9462

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public:
3+
bool less(string &s1, string &s2, map<char, int> &m){
4+
int l = min(s1.size(),s2.size());
5+
for(int i=0;i<l;i++){
6+
if(m[s1[i]]<m[s2[i]])
7+
return true;
8+
if(m[s1[i]]>m[s2[i]])
9+
return false;
10+
}
11+
if(s1.size() <= s2.size())
12+
return true;
13+
return false;
14+
}
15+
bool isAlienSorted(vector<string>& words, string order) {
16+
map<char, int> m;
17+
int i=0;
18+
for(char &a:order){
19+
m.insert(pair<char, int>(a,i));
20+
i++;
21+
}
22+
23+
for(int i=1;i<words.size();i++){
24+
if(!less(words[i-1],words[i],m))
25+
return false;
26+
}
27+
return true;
28+
}
29+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
public:
3+
bool canReorderDoubled(vector<int>& A) {
4+
sort(A.begin(),A.end());
5+
unordered_map<int,int> used;
6+
for(auto &i:A){
7+
if(used.find(i) == used.end())
8+
used.insert(pair<int,int>(i,1));
9+
else
10+
used[i] ++;
11+
}
12+
13+
for(int i=0;i<A.size();i++){
14+
if((used.find(A[i]) != used.end() ) && (used[A[i]] != 0 ) ){
15+
used[A[i]] --;
16+
int d = A[i] * 2;
17+
if(d < 0)
18+
d = A[i] / 2;
19+
if((used.find(d) != used.end()) && (used[d] != 0)){
20+
used[d] --;
21+
}
22+
else
23+
return false;
24+
}
25+
}
26+
return true;
27+
}
28+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Solution {
2+
public:
3+
int lexicographic(vector<string>& A, vector<int> &col){
4+
for (int i=0; i<A.size()-1; i++){
5+
for(auto &j:col){
6+
if (A[i][j] < A[i+1][j])
7+
break;
8+
if (A[i][j] > A[i+1][j])
9+
return false;
10+
}
11+
}
12+
return true;
13+
}
14+
15+
int minDeletionSize(vector<string>& A) {
16+
int l = A.size();
17+
int w = A[0].size();
18+
19+
vector<int> col;
20+
int res=0;
21+
for(int i=0;i<w;i++){
22+
col.push_back(i);
23+
if(!lexicographic(A,col)){
24+
col.pop_back();
25+
res += 1;
26+
}
27+
}
28+
return res;
29+
}
30+
};
31+

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,4 +651,10 @@
651651

652652
[951.Flip-Equivalent-Binary-Trees](Algorithms/951.Flip-Equivalent-Binary-Trees/solution.cpp)
653653

654-
[952.Largest-Component-Size-by-Common-Factor](Algorithms/952.Largest-Component-Size-by-Common-Factor/solution.cpp)
654+
[952.Largest-Component-Size-by-Common-Factor](Algorithms/952.Largest-Component-Size-by-Common-Factor/solution.cpp)
655+
656+
[953.Verifying-an-Alien-Dictionary](Algorithms/953.Verifying-an-Alien-Dictionary/solution.cpp)
657+
658+
[954.Array-of-Doubled-Pairs](Algorithms/954.Array-of-Doubled-Pairs/solution.cpp)
659+
660+
[955.Delete-Columns-to-Make-Sorted-II](Algorithms/955.Delete-Columns-to-Make-Sorted-II/solution.cpp)

0 commit comments

Comments
 (0)