Skip to content

Latest commit

 

History

History
22 lines (20 loc) · 435 Bytes

650.md

File metadata and controls

22 lines (20 loc) · 435 Bytes

650. 2 Keys Keyboard

Solution 1 (time O(sqrt(n)), space O(n))

class Solution(object):
    def minSteps(self, n):
        """
        :type n: int
        :rtype: int
        """
        ans = 0
        i = 2
        while i * i <= n:
            while n % i == 0:
                n = n / i
                ans += i
            i += 1
        if n > 1:
            ans += n
        return ans