Simple C++ Solution


  • 2
    W
        bool isStrobogrammatic(string num) {
            for (int i = 0, j = num.size()-1; i<=j; i++, j--){
                if (num[i] == num[j]){
                    if (num[i] != '0' && num[i] != '1' && num[i] != '8') return false;
                }
                else if (!((num[i] == '6' && num[j] == '9') || (num[i] =='9'&&num[j] =='6'))) return false;
            }
            return true;
        }

Log in to reply
 

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