Java simple and concise 9 ms


  • 0
    K
    public class Solution {
        public int minSteps(int n) {
            int res = 0;
            int i=2;
            while(i<=n)
            {
                if(n%i == 0)
                {
                    n = n/i;
                    res+= i;
                    i=2;
                    continue;
                }
                i++;
            }
            
            return res;
        }
    }
    

Log in to reply
 

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