Simple mathematical analysis


  • 0
    C

    class Solution {
    public:
    int integerBreak(int n) {
    if(n==2)
    return 1;
    else if(n==3)
    return 2;
    else{
    int mod3=n%3;
    switch(mod3){
    case 0:
    return pow(3,n/3);
    case 1:
    return pow(3,(n/3-1)) * 4;
    default : //for modulo 2
    return pow(3,n/3)*2;
    }
    }
    }
    };


  • 0
    K

    Hit Ctrl+K to indent your code so it displays properly


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.