Участник:Kiranov dmitry/task5

Материал из DISCOPAL
Перейти к: навигация, поиск

ссылка: https://leetcode.com/problems/2-keys-keyboard

class Solution:
   def minSteps(self, n: int) -> int:
       res = []
       res.append(0)
       maxdivision1 = 0
       maxdivision2 = 0
       for i in range(4):
           res.append(i+2)
       if n <= 5:
           return res[n-1]
       else:
           i = 5
           while i < n:
               for j in range(len(res)):
                   if (i+1) % (j+1) == 0:
                       maxdivision1 = j+1
                       if maxdivision1 > maxdivision2 :
                           maxdivision2 = maxdivision1
               if maxdivision2 == 1:
                   maxdivision2 = i+1
                   res.append(i+1)
               else:
                   res.append(int(res[maxdivision2-1] + (i+1)/maxdivision2))
               maxdivision1 , maxdivision2 = 0, 0
               i+=1
       return res[n-1]