C++ Used a char array, 0ms


  • 0
    T
    class Solution {
    public:
        bool isStrobogrammatic(string num) {
            char stob[10]={'0','1',' ',' ',' ',' ','9',' ','8','6'};
            int l=0, n=num.length();
            for(int i=0;i<=n/2;i++) {
                if(num[i]!=stob[num[n-i-1]-'0']) return false;
            }
            return true;
        }
    };
    

Log in to reply
 

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