246. Strobogrammatic Number
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
Write a function to determine if a number is strobogrammatic. The number is represented as a string.
Example 1:
Input: "69"
Output: true
Example 2:
Input: "88"
Output: true
Example 3:
Input: "962"
Output: false
class Solution {
// ask if 00 is a valid strobogrammatic number! Here is true!
public boolean isStrobogrammatic(String num) {
for(int i = 0, j = num.length() -1; i <= j; i++, j--){
if(!"00 11 696 88".contains(num.charAt(i) + "" + num.charAt(j)))
return false;
}
return true;
}
}
class Solution(object):
def isStrobogrammatic(self, num):
"""
:type num: str
:rtype: bool
"""
s = set(['00', '11', '69', '96', '88'])
i , j = 0, len(num) - 1
while(i <= j):
if '{}{}'.format(num[i], num[j]) not in s:
print('{}{}'.format(num[i], num[j]))
return False
i+=1
j-=1
return True