Re: [閒聊] 每日leetcode已回收

看板Marginalman作者 (smart0eddie)時間1年前 (2024/07/07 11:12), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串456/1554 (看更多)
2024-07-07 1518. Water Bottles There are numBottles water bottles that are initially full of water. You can exchange numExchange empty water bottles from the market with one full water bottle. The operation of drinking a full water bottle turns it into an empty bottle. Given the two integers numBottles and numExchange, return the maximum number of water bottles you can drink. 暴力解 每次多喝 B 瓶 每 E 個空瓶可以去換一瓶滿的 會剩下 R 個空瓶 int numWaterBottles(int numBottles, int numExchange) { int count = numBottles; int rest = 0; int tmp_numBottles = 0; while (numBottles + rest >= numExchange) { tmp_numBottles = (numBottles + rest) / numExchange; rest = (numBottles + rest) % numExchange; count += tmp_numBottles; numBottles = tmp_numBottles; } return count; } 一行的數學姐看不懂 有大師能用姆咪也看得懂的方式解釋一下嗎 [Python] One line Math Solution O(1) beating 100% -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 73.173.211.221 (美國) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1720321943.A.C8F.html
文章代碼(AID): #1cYWUNoF (Marginalman)
討論串 (同標題文章)
文章代碼(AID): #1cYWUNoF (Marginalman)