Java solution competes 99%


  • 0
    L

    '''
    class Solution {
    public int minSteps(int n) {
    int min = 0;
    int num = 3;
    while(n%2 == 0){
    min += 2;
    n = n/2;
    }
    if(n == 1){
    return min;
    }
    if(n%2 != 0){
    int i = n/2;
    for(i = n/2; i>0; i--){
    if(n%i == 0){
    break;
    }
    }
    min = min + n/i + minSteps(i);
    }
    return min;
    }
    }

    '''


Log in to reply
 

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