246. Strobogrammatic Number

首先找到那几种是可以Strobogrammatic的

然后一个walker,一个runner,然后walker <= runner的时候比较是否是一组一组的

要等于因为2就并不是Strobogrammatic

 1     public boolean isStrobogrammatic(String num) {
 2         Map<Character, Character> map = new HashMap<Character, Character>();
 3         map.put(‘6‘, ‘9‘);
 4         map.put(‘9‘, ‘6‘);
 5         map.put(‘1‘, ‘1‘);
 6         map.put(‘8‘, ‘8‘);
 7         map.put(‘0‘, ‘0‘);
 8         int walker = 0;
 9         int runner = num.length() - 1;
10         while(walker <= runner) {
11             if(map.containsKey(num.charAt(walker)) && map.get(num.charAt(walker)) == num.charAt(runner)) {
12                 walker++;
13                 runner--;
14             } else {
15                 return false;
16             }
17         }
18         return true;
19     }
时间: 2024-10-13 04:12:37

246. Strobogrammatic Number的相关文章

Leetcode 246: Strobogrammatic Number

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. For example, the numbers "69", "

[LeetCode] 246. Strobogrammatic Number 对称数

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. For example, the numbers "69", "

[LeetCode] 248. Strobogrammatic Number III 对称数III

A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Write a function to count the total strobogrammatic numbers that exist in the range of low <= num <= high. For example,Given low = "50&qu

[LeetCode] 247. Strobogrammatic Number II 对称数II

A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Find all strobogrammatic numbers that are of length = n. For example,Given n = 2, return ["11","69","88","96"

[LeetCode#246] Missing Ranges Strobogrammatic Number

Problem: 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. For example, the numbers "69"

[LeetCode] Strobogrammatic Number 对称数

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. For example, the numbers "69", "

LeetCode Strobogrammatic Number II

原题链接在这里:https://leetcode.com/problems/strobogrammatic-number-ii/ 题目: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Find all strobogrammatic numbers that are of length = n. For example,Given

LeetCode Strobogrammatic Number

原题链接在这里:https://leetcode.com/problems/strobogrammatic-number/ 题目: 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 r

248. Strobogrammatic Number III

题目: A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down). Write a function to count the total strobogrammatic numbers that exist in the range of low <= num <= high. For example,Given low = "5