当前位置:网站首页>leetcode:55. Jumping game [classic greed]
leetcode:55. Jumping game [classic greed]
2022-06-24 22:04:00 【Review of the white speed Dragon King】

analysis
Maintain the current position , And the farthest position to be reached next time in the current maximum range maxPos
The current walking position is [cur, maxPos] But in the process of walking , Walk and watch the next maxPos, Then when cur Go to the previous maxPos when , next maxPos Come out, too
So this is walking at the foot , Looking at the greed ahead
The greedy strategy is : I walk wherever I can , See the longest distance you can walk next time
The next longest distance I can walk is the largest in the current range nums[i] + i
Finally, take a look at cur Can you get there len(nums) - 1 that will do
ac code
class Solution:
def canJump(self, nums: List[int]) -> bool:
cur, maxPos = 0, 0
# The maximum range that can be taken in this step
while cur < maxPos + 1:
# The current position , To the farthest point you can walk
for i in range(cur, maxPos + 1):
# Update the next farthest location
maxPos = max(maxPos, nums[i] + i)
# If you come to the end step by step
if cur == len(nums) - 1:
return True
# cur and i Corresponding
cur += 1
return False
summary
Jumping game Follow The car refueling game is almost the same
Classic greed
边栏推荐
- Maximum flow problem
- Binary search tree template
- Object. Defineproperty and reflect Fault tolerance of defineproperty
- MySQL gets fields and comments by indicating
- [theory] deep learning in the covid-19 epic: a deep model for urban traffic revitalization index
- Multithreaded finalization
- Practice of hierarchical management based on kubesphere
- (to be added) games101 job 7 improvement - knowledge you need to know to realize micro surface model
- Two implementation methods of stack
- Machine learning: linear regression
猜你喜欢
![[200 opencv routines] 209 Color image segmentation in HSV color space](/img/fa/9a40015cbcf9c78808f147e510be4c.jpg)
[200 opencv routines] 209 Color image segmentation in HSV color space
![[notes of Wu Enda] multivariable linear regression](/img/b1/60a702aaca58b0afa57ac2f552dabf.png)
[notes of Wu Enda] multivariable linear regression

You are using pip version 21.1.2; however, version 22.1.2 is available

Interviewer: you said you are proficient in redis. Have you seen the persistent configuration?

滤波数据分析

Maximum flow problem

权限想要细化到按钮,怎么做?

降低pip到指定版本(通过PyCharm升级pip,在降低到原来版本)

A deep learning model for urban traffic flow prediction with traffic events mined from twitter

Notes on writing questions (18) -- binary tree: common ancestor problem
随机推荐
Suspend component and asynchronous component
刷题笔记(十八)--二叉树:公共祖先问题
[untitled]
Cannot find reference 'imread' in 'appears in pycharm__ init__. py‘
机器学习:线性回归
(to be added) games101 job 7 improvement - knowledge you need to know to realize micro surface model
[notes of Wu Enda] convolutional neural network
[camera Foundation (II)] camera driving principle and Development & v4l2 subsystem driving architecture
Introduce the overall process of bootloader, PM, kernel and system startup
基于 KubeSphere 的分级管理实践
Flutter 如何使用在线转码工具将 JSON 转为 Model
How to resolve the 35 year old crisis? Sharing of 20 years' technical experience of chief architect of Huawei cloud database
Byte software testing basin friends, you can change jobs. Is this still the byte you are thinking about?
[untitled]
如何抓手机的包进行分析,Fiddler神器或许能帮到您!
Application practice | massive data, second level analysis! Flink+doris build a real-time data warehouse scheme
火狐拖放后,总会默认打开百度搜索,如果是图片,则会打开图片。
Xinlou: Huawei's seven-year building journey of sports health
01--- conditions for interference of two trains of waves at the meeting place
二叉搜索树模板