Skip to content

Instantly share code, notes, and snippets.

@freelze
Created September 28, 2017 12:03
Show Gist options
  • Save freelze/07156790a9e874d2732be0348e5199fe to your computer and use it in GitHub Desktop.
Save freelze/07156790a9e874d2732be0348e5199fe to your computer and use it in GitHub Desktop.
Runtime: 3 ms , Your runtime beats 2.01 % of cpp submissions.
class Solution {
public:
int integerBreak(int n) {
if(n == 2 || n == 3) return n-1;
if(n == 4) return 4;
int num = n/3;
int sum = 1;
if(n%3 == 1) sum = 4, --num;
else if(n%3 == 2) sum = 2;
while(num--)
{
sum*=3;
}
return sum;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment