Skip to content

Commit b8bf633

Browse files
committed
0953 added.
1 parent 6493055 commit b8bf633

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
project(A)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
6+
add_executable(A main.cpp)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/// Source : https://leetcode.com/problems/verifying-an-alien-dictionary/
2+
/// Author : liuyubobobo
3+
/// Time : 2018-12-08
4+
5+
#include <iostream>
6+
#include <vector>
7+
#include <unordered_map>
8+
9+
using namespace std;
10+
11+
12+
/// Transform and Compare
13+
/// Time Complexity: O(n)
14+
/// Space Complexity: O(1)
15+
class Solution {
16+
public:
17+
bool isAlienSorted(vector<string>& words, string order) {
18+
19+
unordered_map<char, char> map;
20+
for(int i = 0; i < order.size(); i ++)
21+
map[order[i]] = 'a' + i;
22+
23+
for(string&word: words)
24+
for(char& c: word)
25+
c = map[c];
26+
27+
for(int i = 1; i < words.size(); i ++)
28+
if(words[i - 1] > words[i])
29+
return false;
30+
return true;
31+
}
32+
};
33+
34+
35+
int main() {
36+
37+
return 0;
38+
}

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,4 +612,7 @@ email: [liuyubobobo@gmail.com](mailto:liuyubobobo@gmail.com)
612612
| 950 | [Reveal Cards In Increasing Order](https://leetcode.com/problems/reveal-cards-in-increasing-order/) | [solution](https://leetcode.com/problems/reveal-cards-in-increasing-order/solution/) | [C++](0950-Reveal-Cards-In-Increasing-Order/cpp-0950/) | | |
613613
| 951 | [Flip Equivalent Binary Trees](https://leetcode.com/problems/flip-equivalent-binary-trees/) | [solution](https://leetcode.com/problems/flip-equivalent-binary-trees/solution/) | [C++](0951-Flip-Equivalent-Binary-Trees/cpp-0951/) | | |
614614
| 952 | [Largest Component Size by Common Factor](https://leetcode.com/problems/largest-component-size-by-common-factor/) | [solution](https://leetcode.com/problems/largest-component-size-by-common-factor/solution/) | [C++](0952-Largest-Component-Size-by-Common-Factor/cpp-0952/) | | |
615+
| 953 | [isAlienSorted](https://leetcode.com/problems/verifying-an-alien-dictionary/) | [solution](https://leetcode.com/problems/verifying-an-alien-dictionary/solution/) | [C++](0953-isAlienSorted/cpp-0953/) | | |
616+
| | | | | | |
617+
| | | | | | |
615618
| | | | | | |

0 commit comments

Comments
 (0)