-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path343.java
More file actions
31 lines (31 loc) · 985 Bytes
/
343.java
File metadata and controls
31 lines (31 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public int integerBreak(int n) {
if(n<4) return n-1;
if(n==4) return 4;
int res=1;
while (n>4){
n-=3;
res*=3;
// System.out.println(res);
}
return res*n;
}
}
__________________________________________________________________________________________________
sample 31468 kb submission
class Solution {
public int integerBreak(int n) {
int[] result = new int[n + 1];
for (int i = 2; i <= n; i++) {
int curMax = 0;
for (int j = 1; j < i; j++) {
curMax = Math.max(curMax, Math.max(j, result[j]) * (i - j));
}
result[i] = curMax;
}
return result[n];
}
}
__________________________________________________________________________________________________