0%

剑指offer-14

题目

结果

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public int cuttingRope(int n) {
if (n <= 3) {
return n - 1;
}
int x = n / 3;
int b = n % 3;
if (b == 0) {
return (int) Math.pow(3, x);
} else if (b == 1) {
return (int) Math.pow(3, x - 1) * 4;
} else {
return (int) Math.pow(3, x) * 2;
}
}
}

复杂度

时间复杂度:O(1)

空间复杂度:O(1)