Each day a plant is growing by upSpeed
meters. Each night that plant's height decreases by downSpeed
meters due to the lack of sun heat. Initially, plant is 0 meters tall. We plant the seed at the beginning of a day. We want to know when the height of the plant will reach a certain level.
Example
For upSpeed = 100
, downSpeed = 10
, and desiredHeight = 910
, the output should begrowingPlant(upSpeed, downSpeed, desiredHeight) = 10
.
我的解答:
import math def growingPlant(upSpeed, downSpeed, desiredHeight): if upSpeed > desiredHeight: return 1 return math.ceil((desiredHeight - upSpeed) / (upSpeed - downSpeed)) + 1
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
一样滴