-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrobogrammatic.java
More file actions
30 lines (28 loc) · 884 Bytes
/
strobogrammatic.java
File metadata and controls
30 lines (28 loc) · 884 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.*;
public class strobogrammatic {
public static void main(String[] args) {
String n = "9006";
System.out.println("Is " + n + " is Strobogrammatic? " + is_Strobogrammatic(n));
}
public static boolean is_Strobogrammatic(String n) {
if (n == null || n.length() == 0) {
return true;
}
HashMap<Character, Character> map = new HashMap<Character, Character>();
map.put('0', '0');
map.put('1', '1');
map.put('8', '8');
map.put('6', '9');
map.put('9', '6');
int left = 0;
int right = n.length() - 1;
while (left <= right) {
if (!map.containsKey(n.charAt(right)) || n.charAt(left) != map.get(n.charAt(right))) {
return false;
}
left++;
right--;
}
return true;
}
}