File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 1
1
package easy ;
2
2
3
+ import java .util .HashMap ;
3
4
import java .util .HashSet ;
5
+ import java .util .Map ;
4
6
import java .util .Set ;
5
7
6
8
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 ) {
8
30
Set <Character > set = new HashSet ();
9
31
set .add ('0' );
10
32
set .add ('1' );
You can’t perform that action at this time.
0 commit comments