Clicky

Leetcode 246 "Strobogrammatic Number"

January 1, 0001

246. Strobogrammatic Number

Result

Runtime: 0 ms, faster than 100.00% of Java online submissions for Strobogrammatic Number.

Memory Usage: 36.5 MB, less than 95.52% of Java online submissions for Strobogrammatic Number.

class Solution {
    public boolean isStrobogrammatic(String num) {
        int left = 0;
        int right = num.length() - 1;
        while(left <= right) {
            if(num.charAt(left) == '0' && num.charAt(right) == '0') {
                left++;
                right--;
                continue;
            }
            if(num.charAt(left) == '1' && num.charAt(right) == '1') {
                left++;
                right--;
                continue;
            }
            if(num.charAt(left) == '8' && num.charAt(right) == '8') {
                left++;
                right--;
                continue;
            }
            if(num.charAt(left) == '6' && num.charAt(right) == '9') {
                left++;
                right--;
                continue;
            }
            if(num.charAt(left) == '9' && num.charAt(right) == '6') {
                left++;
                right--;
                continue;
            }
            return false;
        }
        return true;        
    }
}