Simple 0ms Java solution


  • 0
    C
    public class Solution {
        public boolean isStrobogrammatic(String num) {
            char[] strnum = num.toCharArray();
            int len = strnum.length;
            for(int i=0;i<=len/2;i++){
                if(strnum[i]=='2' || strnum[i]=='3' || strnum[i]=='4'
                    || strnum[i]=='5' || strnum[i]=='7'){
                        return false;
                    }
                if((strnum[i]=='1' || strnum[i]=='0' || strnum[i]=='8') && strnum[len-i-1]!=strnum[i])
                    return false;
                if((strnum[i]=='6' && strnum[len-i-1]!='9') || (strnum[i]=='9' && strnum[len-i-1]!='6'))
                    return false;
            }
            return true;
        }
    }

Log in to reply
 

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