246 Strobogrammatic Number I
246 Strobogrammatic Number I / / ac class Solution { public boolean isStrobogrammatic(String num) { HashMap<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; int j = num.length() - 1; while(i <= j){ if(!map.containsKey(num.charAt(i))) return false; // if(num.charAt(i) != map.get(num.charAt(j))){. This ape if(map.get(num.charAt(i)) != num.charAt(j)){ return false; } i++; j--; } return true; } }
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
Write a function to determine if a number is strobogrammatic. The number is represented as a string.
Example 1:
Input: "69" Output: true
Example 2:
Input: "88" Output: true
Example 3:
Input: "962" Output: false
posted on 2018-08-10 14:40 猪猪🐷 阅读(90) 评论(0) 收藏 举报
浙公网安备 33010602011771号