Java 0ms 5-line solution without using HashMap


  • 1
    public boolean isStrobogrammatic(String num) {
        int[] map = new int[10];
        map[0]=0;map[1]=1;map[2]=-1;map[3]=-1;map[4]=-1;map[5]=-1;map[6]=9;map[7]=-1;map[8]=8;map[9]=6;
        int lo = 0, hi = num.length()-1;
        while(lo<=hi) if(num.charAt(hi--)-'0' != map[num.charAt(lo++)-'0']) return false;
        return true;
    }
    

  • 0
    J

    very smart solution.


Log in to reply
 

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