Java two pointers solution


  • 0
    Q
    public class Solution {
        public boolean isStrobogrammatic(String num) {
            int i = 0 , j = num.length() - 1;
            while(j >= i){
                if(!isPair(num.charAt(i), num.charAt(j)))
                    return false;
                i++;
                j--;
            }
            return true;
        }
        public boolean isPair(int a, int b){
            if((a == '1' && b == '1')
            || (a == '6' && b == '9')
            || (a == '8' && b == '8')
            || (a == '9' && b == '6')
            || (a == '0' && b == '0'))
                return true;
            return false;
        }
    }
    

Log in to reply
 

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