-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathmain.cpp
36 lines (33 loc) · 814 Bytes
/
main.cpp
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
33
34
35
36
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <cstdlib>
using namespace std;
class Solution {
private:
map<char, char> digit_map = {{'6', '9'}, {'9', '6'}, {'8', '8'}, {'1', '1'}, {'0', '0'}};
public:
bool isStrobogrammatic(string str) {
int left = 0, right = str.size() - 1;
while (left <= right) {
char c1 = str[left], c2 = str[right];
if (digit_map.count(c1) &&
digit_map.count(c2) &&
digit_map[str[left]] == digit_map[str[right]]) {
left++;
right--;
} else {
return false;
}
}
return true;
}
};
int main() {
Solution sol;
cout << sol.isStrobogrammatic("818") << endl;
cout << sol.isStrobogrammatic("414") << endl;
cout << sol.isStrobogrammatic("0") << endl;
return 0;
}