simple c++ solution, no hash no list


  • 0
        bool isStrobogrammatic(string num) {
            char *search="23457";
            if(num.find_first_of(search)!=string::npos)
                return false;
            int left=0;
            int right=num.size()-1;
            while(left<=right){
                if(num[left]==num[right]&&num[left]!='6'&&num[left]!='9'||num[left]=='9'&&num[right]=='6'||num[left]=='6'&&num[right]=='9'){
                    left++;
                    right--;
                }
                else
                    return false;
            }
            return true;
        }
    

Log in to reply
 

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