1ms Java Solution using hashmap


  • 0
    V

    public class Solution {

    public boolean isStrobogrammatic(String num) {
        HashMap<Character, Character> map = new HashMap<Character, Character>();
        map.put('0','0');
        map.put('1','1');
        map.put('6','9');
        map.put('9','6');
        map.put('8','8');
        for(int i = 0, j = num.length()-1; i <= j; i++, j--) {
            if(!map.containsKey(num.charAt(i))){
                return false;
            }
            if(map.get(num.charAt(i)) != num.charAt(j)) {
                return false;
            }
        }
        return true;
    }
    

    }


Log in to reply
 

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