1 parent 3ff0945 commit 4de3466Copy full SHA for 4de3466
1 file changed
solutions/343. Integer Break/AC_Math.java
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 找规律,最简单的方法就是多试几个数,发现规律,然后归纳
3
+ *
4
5
+ */
6
+public class IntegerBreak {
7
+ public static int integerBreak(int n) {
8
+ int result = 0;
9
+ if(n == 1) return 1;
10
+ if(n >= 2 && n <= 3) return n - 1;
11
+
12
+ if(n >= 4 && n < 59){
13
+ if(n % 3 == 1)
14
+ result = (int) (Math.pow(3, n / 3 - 1) * 4);
15
+ else if(n % 3 == 0)
16
+ result = (int) Math.pow(3, n / 3);
17
+ else
18
+ result = (int) (Math.pow(3, n / 3) * 2);
19
+ }
20
+ return result;
21
22
+}
0 commit comments