-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegerBreak.java
More file actions
39 lines (32 loc) · 796 Bytes
/
IntegerBreak.java
File metadata and controls
39 lines (32 loc) · 796 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
/*50 / 50 test cases passed.
Status: Accepted
Runtime: 0 ms
Beats other java submission by 100%
*/
class IntegerBreak {
public int integerBreak(int n) {
int error= 2066242608;
if(n>58)
{
return error;
}
else if(n==3 || n==2)
return n-1;
else
{
if(n%3 ==2){
return (int)Math.pow(3,n/3)*2;
}
else if(n%3 ==1)
{
int ctr=0;
return (int)Math.pow(3,(n-4)/3)*4;
}
else
{
int ctr=0;
return (int) Math.pow(3,n/3);
}
}
}
}