lintcode 644 镜像数字

 

 模拟:从左到右扫一遍,看对应位置是不是mirror word.

class Solution {
public:
    /**
     * @param num: a string
     * @return: true if a number is strobogrammatic or false
     */
     //两个数字中心对称 且 它们是镜像数字,即旋转180度等于另一个数字 
    bool isStrobogrammatic(string &num) {
        // write your code here
        std::vector<int> mp(256, 0);
        //定义映射关系
        mp['0'] = '0';
        mp['1'] = '1';
        mp['6'] = '9';
        mp['8'] = '8';
        mp['9'] = '6';
        
        for(int i=0; i<num.size()/2 + 1 ; i++){
            int j = num.size()-1-i;
            if(mp[num[i]] != num[j])
                return false;
        }
        return true;
    }
};
原文地址:https://www.cnblogs.com/Bella2017/p/11441941.html