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

 

posted on 2022-04-09 13:34  阳光明媚的菲越  阅读(34)  评论(0编辑  收藏  举报