题解 | #剪绳子#
剪绳子
https://www.nowcoder.com/practice/57d85990ba5b440ab888fc72b0751bf8
# from numpy import number # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param n int整型 # @return int整型 # class Solution: def cutRope(self , n: int) -> int: # write code here if n<=3: return n-1 res = 1 if n ==4: return 4 while n >4: n -= 3 res *= 3 return res *n