Created
September 28, 2017 12:03
-
-
Save freelze/07156790a9e874d2732be0348e5199fe to your computer and use it in GitHub Desktop.
Runtime: 3 ms , Your runtime beats 2.01 % of cpp submissions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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