Simple C++ solution


  • 1
    J
    bool isStrobogrammatic(string num) {
        string t = num;
        unordered_map<char, char> hmap = {{'0', '0'}, {'1', '1'}, {'6','9'}, {'8','8'}, {'9', '6'}};
        for(int i = 0; i<t.length(); i++) {
            if(!hmap.count(t[i])) return false;
            t[i] = hmap[t[i]];
            if(t[i] != num[num.size() - i - 1])
                return false;
        }
    
        return true;
    }

Log in to reply
 

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