An easy solution using array


  • 0
    C
    public boolean isStrobogrammatic(String num) {
            int[] table = new int[]{0, 1, -1, -1, -1, -1, 9, -1, 8, 6};
            int start = 0, end = num.length() - 1;
            while (start <= end) {
                if (table[num.charAt(start) - '0'] == -1 || (table[num.charAt(start++) - '0'] != num.charAt(end--) - '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.