Leetcode之Jump Game问题
来源:互联网 发布:php 析构函数的用法 编辑:程序博客网 时间:2024/06/05 23:51
问题描述:
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 = [2,3,1,1,4]
, return true
.
A = [3,2,1,0,4]
, return false
问题来源:Jump Game (详细地址:https://leetcode.com/problems/jump-game/description/)
思路:
先来讲讲题目的意思吧,大致翻译一下:
给定一个一维数组,其中的元素都是非负整数,我们最开始处于数组的最开始位置,数组中的元素代表你能往前移动的最大的步数,最后需要确定的是能不能到达数组的最后一个位置。
相信读完题目,大部分人自然而然就想到了动态规划(Dynamic programming)的思想了,当然也有人说是贪心(Greedy algorithm),每一步取得局部最优结果,最后希望取到全局最优.好吧,好像都能讲的通。下面我采用的是一个局部变量(local)和一个全局变量(global)。
local:当前位置能够跳到哪;
global:截止到当前位置,能够跳到的最大位置,相比local来讲,global更加强调的是全局的意思,而不是当下(好像确实贪心靠谱些哈)
代码:
- Leetcode之Jump Game问题
- Leetcode之Jump Game II 问题
- LeetCode 之 Jump Game
- leetcode之Jump Game
- leetcode 之 Jump Game
- LeetCode之Jump Game
- Leetcode 之 Jump Game
- leetcode之jump game
- leetcode之Jump Game
- 【Leetcode】之 Jump Game
- leetcode之Jump Game && Jump Game II
- Leetcode之Jump Game & Jump Game II
- LeetCode之Jump Game II
- 【Leetcode】之Jump Game II
- leetcode之jump game II
- leetcode-55 Jump Game 最远距离问题
- LeetCode 之 Jump Game(贪心算法)
- LeetCode第45之 Jump Game II
- offset, client, scroll
- 深入分析类与对象--构造方法与匿名对象
- layerlist添加阴影效果
- 购物车.
- 解析JSON数据的方法
- Leetcode之Jump Game问题
- ArrayList LinkedList Vector的区别
- 第二周-项目0-宣告主权
- Swift 类型转换
- 纯css label写轮播图
- Vue项目4、Vuex
- 2017.9.21 道路修建(noi2011) 思考记录
- 次方求模
- Android中关于FTP的文件上传和下载