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.
For example, the numbers "69", "88", and "818" are all strobogrammatic.
Tips:
走一遍,只要左右不是00 11 88 696就是错的。
Code:
public class Solution {
public boolean isStrobogrammatic(String num) {
if (num == null || num.length() == 0) {
return true;
}
int left = 0, right = num.length() - 1;
while (left <= right) {
if (!"00 11 88 696".contains(num.charAt(left) + "" + num.charAt(right))) {
return false;
}
left++;
right--;
}
return true;
}
}