LeetCode 1518. 换水问题

题目链接https://leetcode.cn/problems/water-bottles/description/

  1. class Solution {
  2. public int numWaterBottles(int numBottles, int numExchange) {
  3. int bots = numBottles;
  4. while(numBottles / numExchange > 0){
  5. int a = numBottles / numExchange;
  6. int b = numBottles % numExchange;
  7. bots=a+bots;
  8. numBottles = a+b;
  9. }
  10. return bots;
  11. }
  12. }

9ec21187050142788793a62b2714874d.png

发表评论

表情:
评论列表 (有 0 条评论,99人围观)

还没有评论,来说两句吧...

相关阅读

    相关 [LeetCode] 626. 座位

    小美是一所中学的信息科技老师,她有一张 `seat` 座位表,平时用来储存学生名字和与他们相对应的座位 id。 其中纵列的 id 是连续递增的。小美想改变相邻俩学生的座位 ?

    相关 leetcode题->两数之和

    给定一个整数数组 `nums` 和一个目标值 `target`,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。 你可以假设每种输入只会对应一个答案。但是