My java solution using an array


  • 0
    B
    public boolean isStrobogrammatic(String num) {
        if(num==null||num.length()==0) return true;
        int[] same={0,1,-1,-1,-1,-1,9,-1,8,6};
        for(int i=0; i<=num.length()/2; i++){
            int cur=num.charAt(i)-'0';
            int cur1=num.charAt(num.length()-1-i)-'0';
            if(same[cur]!=cur1) return false;
        }
        return true;
    }

Log in to reply
 

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