Clean Java Solution


  • 0
    M
        public boolean isStrobogrammatic(String num) {
            if (num == null) return false;
            int i = 0, j = num.length() - 1;
            while (i <= j) {
                if (!isSG(num.charAt(i++), num.charAt(j--))) return false;
            }
            return true;
        }
        private boolean isSG(char a, char b) {
            if (a == b) return a == '1' || a == '0' || a == '8';
            return a == '6' && b == '9' || a == '9' && b == '6';
        }
    

Log in to reply
 

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