C++ 0ms 6 lines solution


  • 0
    bool isStrobogrammatic(string num) {
        unordered_map<char,char>m{{'6','9'},{'9','6'},{'8','8'},{'1','1'},{'0','0'}};
        string::iterator head=num.begin();
        string::iterator tail=num.end()-1;
        while(head<tail) if(m[*head++]!=*tail--) return false;
        if(head==tail) return *head=='0'||*head=='1'||*head=='8';
        return true;
    }
    

Log in to reply
 

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