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
一样滴
膜拜大佬