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;
    }
};

 

posted @ 2019-09-01 12:21  爱学英语的程序媛  阅读(332)  评论(0编辑  收藏  举报