Simple c++ solution


  • 0
    M
    class Solution {
    public:
        bool isStrobogrammatic(string num) {
            for(int i=0;i<=(num.size()-1)/2;i++){
                if(num[i] == '1' && num[num.size()-1-i] == '1')
                    continue;
                if(num[i] == '8' && num[num.size()-1-i] == '8')
                    continue;
                if(num[i] == '0' && num[num.size()-1-i] == '0')
                    continue;
                if(num[i] == '6' && num[num.size()-1-i] == '9')
                    continue;
                if(num[i] == '9' && num[num.size()-1-i] == '6')
                    continue;
                return false;
            }
            return true;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.