-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path246.cpp
23 lines (23 loc) · 801 Bytes
/
246.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
bool isStrobogrammatic(string num) {
int n = num.size();
int left = 0;
int right = n - 1;
while (left < right) {
bool flag = false;
if (num[left] == '9' && num[right] == '6') flag = true;
else if (num[left] == '8' && num[right] == '8') flag = true;
else if (num[left] == '6' && num[right] == '9') flag = true;
else if (num[left] == '1' && num[right] == '1') flag = true;
else if (num[left] == '0' && num[right] == '0') flag = true;
if (!flag) return false;
left++;
right--;
}
if (n & 1) {
if (num[left] != '0' && num[left] != '1' && num[left] != '8') return false;
}
return true;
}
};