Strobogrammatic Number
https://leetcode.com/problems/strobogrammatic-number/description/
Thoughts
Code
class Solution {
public:
bool isStrobogrammatic(string num) {
for (int i = 0, j = num.length() - 1; i <= j; ++i, --j) {
if (num[i] == '8' && num[j] == '8' || num[i] == '1' && num[j] == '1' || num[i] == '0' && num[j] == '0' || num[i] == '6' && num[j] == '9' ||
num[i] == '9' && num[j] == '6')
continue;
return false;
}
return true;
}
};Analysis
Last updated