Skip to content

Commit 71a28e6

Browse files
EASY/src/easy/StrobogrammaticNumber.java
1 parent 9041ff6 commit 71a28e6

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

EASY/src/easy/StrobogrammaticNumber.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
package easy;
22

3+
import java.util.HashMap;
34
import java.util.HashSet;
5+
import java.util.Map;
46
import java.util.Set;
57

68
public class StrobogrammaticNumber {
7-
public boolean isStrobogrammatic(String num) {
9+
10+
public boolean isStrobogrammatic_map(String num) {
11+
int i = 0, j = num.length()-1;
12+
Map<Character, Character> map = new HashMap();
13+
map.put('8', '8');
14+
map.put('1', '1');
15+
map.put('0', '0');
16+
if(j == 0) return map.containsKey(num.charAt(i));
17+
18+
map.put('9', '6');
19+
map.put('6', '9');
20+
while(i < j){
21+
if(!map.containsKey(num.charAt(i)) || !map.containsKey(num.charAt(j))) return false;
22+
if(map.get(num.charAt(i)) != num.charAt(j)) return false;
23+
i++;j--;
24+
}
25+
return map.containsKey(num.charAt(i));
26+
}
27+
28+
29+
public boolean isStrobogrammatic_set(String num) {
830
Set<Character> set = new HashSet();
931
set.add('0');
1032
set.add('1');

0 commit comments

Comments
 (0)