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.
思路
1. 0,1,6,8,9可以旋转得到新的数。将给的数左右两个指针遍历
bool isStrobogrammatic(string num) {
int left=0,right=num.size()-1;
vector<int> ref(10,-1);
ref[0]=0;
ref[1]=1;
ref[6]=9;
ref[8]=8;
ref[9]=6;
while(left<=right){
if(ref[num[right]]==-1||ref[num[left]]==-1) return false;
if(ref[num[right]]!=num[left]]) return false;
left++;right--;
}
return true;
}