151. Leetcode 剑指 Offer 14- I. 剪绳子 (贪心算法-基础题目)
生活随笔
收集整理的這篇文章主要介紹了
151. Leetcode 剑指 Offer 14- I. 剪绳子 (贪心算法-基础题目)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?
class Solution:def cuttingRope(self, n: int) -> int:if n <= 3:return n-1a, b = n // 3, n % 3if b == 0:return int(math.pow(3,a))if b == 1:return int(math.pow(3,a-1) * 4)return int(math.pow(3,a) * 2)?
?
總結(jié)
以上是生活随笔為你收集整理的151. Leetcode 剑指 Offer 14- I. 剪绳子 (贪心算法-基础题目)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 150. Leetcode 860. 柠
- 下一篇: 152. Leetcode 剑指 Off