力扣题目:总行驶距离
题目链接:2739.总行驶距离
题目描述
代码思路
直接用数学模拟计算即可
代码纯享版
java
class Solution {
public int distanceTraveled(int mainTank, int additionalTank) {
int sum = 0;
while(additionalTank > 0){
if(mainTank >= 5){
mainTank = mainTank - 5 + 1;
sum += 5;
additionalTank--;
}
else break;
}
return (sum + mainTank) * 10;
}
}