LeetCode 2739. Total Distance Traveled

时间:2023-06-18 12:17:13 来源: 哔哩哔哩

A truck has two fuel tanks. You are given two integers, mainTankrepresenting the fuel present in the main tank in liters and additionalTankrepresenting the fuel present in the additional tank in liters.


【资料图】

The truck has a mileage of 10km per liter. Whenever 5liters of fuel get used up in the main tank, if the additional tank has at least 1liters of fuel, 1liters of fuel will be transferred from the additional tank to the main tank.

Return the maximum distance which can be traveled.

Note: Injection from the additional tank is not continuous. It happens suddenly and immediately for every 5 liters consumed.

Example 1:

Input: mainTank = 5, additionalTank = 10Output: 60Explanation: After spending 5 litre of fuel, fuel remaining is (5 - 5 + 1) = 1 litre and distance traveled is 50km.After spending another 1 litre of fuel, no fuel gets injected in the main tank and the main tank becomes empty.Total distance traveled is 60km.

Example 2:

Input: mainTank = 1, additionalTank = 2Output: 10Explanation: After spending 1 litre of fuel, the main tank becomes empty.Total distance traveled is 10km.

计算距离的,简单题目:

Runtime: 7 ms, faster than 100.00% of Java online submissions for Total Distance Traveled.

Memory Usage: 42.7 MB, less than 100.00% of Java online submissions for Total Distance Traveled.

标签:

X 关闭

X 关闭