7 lines C++ 0ms


  • 0
    class Solution {
    public:
        bool isStrobogrammatic(string num) {
            unordered_map<char, char>m{{'6', '9'}, {'9', '6'}, {'1', '1'}, {'0', '0'}, {'8', '8'}};
            string s = "";
            for(auto x: num)
                if(!m.count(x)) return false;
                else s.push_back(m[x]);
            reverse(s.begin(), s.end());
            return s == num;
        }
    };
    

Log in to reply
 

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