File tree 1 file changed +28
-25
lines changed
src/main/java/com/fishercoder/solutions 1 file changed +28
-25
lines changed Original file line number Diff line number Diff line change 31
31
*/
32
32
public class _483 {
33
33
34
- /**credit: https://discuss.leetcode.com/topic/82130/java-solution-with-hand-writing-explain*/
35
- public String smallestGoodBase (String n ) {
36
- long nn = Long .parseLong (n );
37
- long res = 0 ;
38
- for (int k = 60 ; k >= 2 ; k --) {
39
- long start = 2 ;
40
- long end = nn ;
41
- while (start < end ) {
42
- long m = start + (end - start ) / 2 ;
34
+ public static class Solution1 {
35
+ /**
36
+ * credit: https://discuss.leetcode.com/topic/82130/java-solution-with-hand-writing-explain
37
+ */
38
+ public String smallestGoodBase (String n ) {
39
+ long nn = Long .parseLong (n );
40
+ long res = 0 ;
41
+ for (int k = 60 ; k >= 2 ; k --) {
42
+ long start = 2 ;
43
+ long end = nn ;
44
+ while (start < end ) {
45
+ long m = start + (end - start ) / 2 ;
43
46
44
- BigInteger left = BigInteger .valueOf (m );
45
- left = left .pow (k ).subtract (BigInteger .ONE );
46
- BigInteger right = BigInteger .valueOf (nn ).multiply (BigInteger .valueOf (m ).subtract (BigInteger .ONE ));
47
- int cmr = left .compareTo (right );
48
- if (cmr == 0 ) {
49
- res = m ;
50
- break ;
51
- } else if (cmr < 0 ) {
52
- start = m + 1 ;
53
- } else {
54
- end = m ;
47
+ BigInteger left = BigInteger .valueOf (m );
48
+ left = left .pow (k ).subtract (BigInteger .ONE );
49
+ BigInteger right = BigInteger .valueOf (nn ).multiply (BigInteger .valueOf (m ).subtract (BigInteger .ONE ));
50
+ int cmr = left .compareTo (right );
51
+ if (cmr == 0 ) {
52
+ res = m ;
53
+ break ;
54
+ } else if (cmr < 0 ) {
55
+ start = m + 1 ;
56
+ } else {
57
+ end = m ;
58
+ }
55
59
}
56
- }
57
60
58
- if (res != 0 ) {
59
- break ;
61
+ if (res != 0 ) {
62
+ break ;
63
+ }
60
64
}
65
+ return "" + res ;
61
66
}
62
-
63
- return "" + res ;
64
67
}
65
68
66
69
}
You can’t perform that action at this time.
0 commit comments