File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ package easy ;
2
+
3
+ import java .util .HashSet ;
4
+ import java .util .Set ;
5
+
6
+ public class StrobogrammaticNumber {
7
+ public boolean isStrobogrammatic (String num ) {
8
+ Set <Character > set = new HashSet ();
9
+ set .add ('0' );
10
+ set .add ('1' );
11
+ set .add ('6' );
12
+ set .add ('8' );
13
+ set .add ('9' );
14
+ char [] nums = num .toCharArray ();
15
+ int i = 0 , j = num .length ()-1 ;
16
+ while (i <= j ){
17
+ if (!set .contains (nums [i ]) || !set .contains (nums [j ])) return false ;
18
+ if (nums [i ] == '6' && nums [j ] != '9' ) return false ;
19
+ else if (nums [i ] == '9' && nums [j ] != '6' ) return false ;
20
+ else if (nums [i ] == '1' && nums [j ] != '1' ) return false ;
21
+ else if (nums [i ] == '8' && nums [j ] != '8' ) return false ;
22
+ else if (nums [i ] == '0' && nums [j ] != '0' ) return false ;
23
+ else {
24
+ i ++; j --;
25
+ }
26
+ }
27
+ return true ;
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments