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