1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 | public class Solution {
boolean rightMapping(char c1, char c2){
if (c1 > c2) return rightMapping(c2,c1);
if (c1 == '0') return c2 == '0';
if (c1 == '1') return c2 == '1';
if (c1 == '6') return c2 == '9';
if (c1 == '8') return c2 == '8';
return false;
}
public boolean isStrobogrammatic(String num) {
char[] arr = num.toCharArray();
int left = 0;
int right = arr.length-1;
while (left <= right){
if (!rightMapping(arr[left++], arr[right--])) return false;
}
return true;
}
}
|
No comments:
Post a Comment