Java Math Solution


  • 0
    public class Solution {
        public int minSteps(int n) {
            if(n == 1) return 0;
            int factor = (int)Math.sqrt(n);
            while(factor > 1) {
                if(n % factor == 0) return minSteps(factor) + minSteps(n/factor);
                factor--;
            }
            return n;
        }
    }

Log in to reply
 

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