File tree 2 files changed +47
-0
lines changed
main/java/com/smlnskgmail/jaman/leetcodejava/medium
test/java/com/smlnskgmail/jaman/leetcodejava/medium
2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .smlnskgmail .jaman .leetcodejava .medium ;
2
+
3
+ import java .util .Arrays ;
4
+
5
+ // https://leetcode.com/problems/reordered-power-of-2/
6
+ public class ReorderedPowerOf2 {
7
+
8
+ private final int input ;
9
+
10
+ public ReorderedPowerOf2 (int input ) {
11
+ this .input = input ;
12
+ }
13
+
14
+ public boolean solution () {
15
+ int [] arr = count (input );
16
+ for (int i = 0 ; i < 31 ; i ++) {
17
+ if (Arrays .equals (arr , count (1 << i ))) {
18
+ return true ;
19
+ }
20
+ }
21
+ return false ;
22
+ }
23
+
24
+ private int [] count (int n ) {
25
+ int [] result = new int [10 ];
26
+ while (n > 0 ) {
27
+ result [n % 10 ]++;
28
+ n /= 10 ;
29
+ }
30
+ return result ;
31
+ }
32
+
33
+ }
Original file line number Diff line number Diff line change
1
+ package com .smlnskgmail .jaman .leetcodejava .medium ;
2
+
3
+ import org .junit .Test ;
4
+
5
+ import static org .junit .Assert .assertTrue ;
6
+
7
+ public class ReorderedPowerOf2Test {
8
+
9
+ @ Test
10
+ public void defaultTest () {
11
+ assertTrue (new ReorderedPowerOf2 (1 ).solution ());
12
+ }
13
+
14
+ }
You can’t perform that action at this time.
0 commit comments