0%

246. Strobogrammatic Number

O(n) time O(1) space

1
2
3
4
5
6
7
8
9
10
11
class Solution {
public:
bool isStrobogrammatic(string num) {
int m[] = {0, 1, -1, -1, -1, -1, 9, -1, 8, 6};
for (int n = num.length(), l = 0, r = n - 1; l <= r; ++l, --r) {
int cl = num[l] - '0', cr = num[r] - '0';
if (m[cl] == -1 || m[cr] == -1 || m[cl] != cr) return false;
}
return true;
}
};