forked from Xunzhuo/Algorithm-Guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12.java
More file actions
52 lines (30 loc) · 584 Bytes
/
Copy path12.java
File metadata and controls
52 lines (30 loc) · 584 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class Solution {
public int cuttingRope(int n) {
if(n==2)
{
return 1;
}
if(n==3)
{
return 2;
}
int count1=0,count2=0;
count1 = n/3;
if(n-count1*3==1&&count1>0)
{
count1-=1;
}
count2 = n-count1*3;
count2 /=2;
int result = 1;
for(int i=1;i<=count1;i++)
{
result*=3;
}
for(int i=1;i<=count2;i++)
{
result*=2;
}
return result;
}
}