简历:The Google Resume: How to Prepare for a Career and Land a Job at Apple, Microsoft, Google, or any Top Tech Company
算法学习书籍:Introduction to Algorithms
编程珠玑:Programming Pearls (2nd Edition)
C++ 学习:The C++ Programming Language, 4th Edition
经典操作系统书籍,龙书:Operating System Concepts
创业:The Start-up of You: Adapt to the Future, Invest in Yourself, and Transform Your Career
Given an array of non-negative integers, you are initially positioned at the first index of the array.
Each element in the array represents your maximum jump length at that position.
Determine if you are able to reach the last index.
For example:
A =
A =
[2,3,1,1,4]
, return true
.
A =
» Solve this problem[3,2,1,0,4]
, return false
.
刚开始各种木有思路,以为要递归或者dp啥的,后来一想从后往前数呗,规律是,遇到为0的话把res=false,再往前看。用j-i来纪录下差的距离的值,然后看下一个A[i], 若A[i]>=j-i, 那么再res=true.这样从头到尾扫一遍。
也可以用dp来做,从 水中的鱼 看到他的总结,很好值得学习,设 jump[i]为剩余的最大步数,于是 jump[i]=max(jump[i-1], A[i-1])-1. 所以只要jump[i]>=n-i, 那么便可以到达结尾。
也可以用dp来做,从 水中的鱼 看到他的总结,很好值得学习,设 jump[i]为剩余的最大步数,于是 jump[i]=max(jump[i-1], A[i-1])-1. 所以只要jump[i]>=n-i, 那么便可以到达结尾。
也可以用dp来做,从 水中的鱼 看到他的总结,很好值得学习,设 jump[i]为剩余的最大步数,于是 jump[i]=max(jump[i-1], A[i-1])-1. 所以只要jump[i]>=n-i, 那么便可以到达结尾。
ReplyDelete有链接么?
我用的DFS搜索,总是超时。
我的下面那个代码就是用dp的,也是水中的鱼的代码。连接在此:http://fisherlei.blogspot.com/search?q=jump+game
Delete我觉得我的第一个代码,从后数还挺好的,因为不用什么复杂的东西。:)
This comment has been removed by the author.
Delete