Re: [閒聊] 每日LeetCode

作者: Rushia (みけねこ的鼻屎)   2023-02-08 09:32:05
45. Jump Game II
給你一個陣列nums,nums[i]表示從這個點可以往後移動幾格,求出從第0格開始,最少
跳幾格可以跳到陣列尾端(題目保證一定可以到陣列尾端)。
Example:
Input: nums = [2,3,1,1,4]
Output: 2
Explanation: The minimum number of jumps to reach the last index is 2. Jump 1
step from index 0 to 1, then 3 steps to the last index.
Input: nums = [2,3,0,1,4]
Output: 2
思路:
1.如果當前走最遠的地方(curr)到不了i,讓curr等於下一次的最遠距離(next)且次數+1。
2.否則不斷更新下次可以走的最遠距離。
3.最後返回次數即可。
JavaCode:
作者: Wardyal (Wardyal)   2023-02-08 09:37:00
你怎麼早上都有時間再寫leetcodeㄚ
作者: Rushia (みけねこ的鼻屎)   2023-02-08 09:41:00
我提早到公司很簡單的上班前寫一寫很快
作者: pandix (麵包屌)   2023-02-08 11:31:00
大師

Links booklink

Contact Us: admin [ a t ] ucptt.com