Re: [閒聊] 每日leetcode已回收
1518.
好懷念喔
這不是小時候的經典數學題嗎
像是那個雞免同籠種樹剪繩子什麼的
// nb for numBottles, ne for numExchange
once operation:
minus ne bottle would return 1 back
so after one op. the bottles number becomes
nb -(ne-1);
however, there would be some side cases
that just need one more bottle so that it
could reach ne to do one more op.
which means we want
nb -ne than +1,
not nb +1 first, and than -ne
so we let nb -1 first than -(ne-1)
the results simply equals to nb -ne
do the op multiple times:
(nb -1) -(ne -1) -(ne -1) …
the missing bottle we -1 first would finally return
since ne >= 2, we can just throw the final bottle away :)
簡單來說
反正喝酒變成尿 不如當初就喝尿
賺錢來花 吃屎來拉
對ㄚ
: : 一行的數學姐看不懂
: : 有大師能用姆咪也看得懂的方式解釋一下嗎
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 27.51.153.137 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1720374634.A.560.html
推
07/08 01:51,
1年前
, 1F
07/08 01:51, 1F
→
07/08 01:53,
1年前
, 2F
07/08 01:53, 2F
推
07/08 01:56,
1年前
, 3F
07/08 01:56, 3F
討論串 (同標題文章)
完整討論串 (本文為第 458 之 1554 篇):