Straight forward Python solution using Recursion.


  • 0
    S

    Straight forward Python solution using Recursion.
    If you still have any questions. Happy to discuss.

    import math
    
    class Solution(object):
        def isPrime(self, a):
            for i in range(2, int(math.sqrt(a)) + 1):
                if a % i == 0:
                    return False
            return True
    
        def minSteps(self, n):
            
            if n == 1:
                return 0
            elif self.isPrime(n):
                return n
            else:
                for i in range(n//2, 1, -1):
                    if n % i == 0:
                        return self.minSteps(i) + n // i

Log in to reply
 

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