55.Jump Game
这种动规的方法时间复杂度是0(n²)
class Solution { public:bool canJump(vector<int>& nums) {int length = nums.size();bool can[length];for(int i = 1;i < length;i++)can[i] = false;can[0] = true;for(int i = 1;i < length;i++){for(int j = i-1;j >= 0;j--){if(can[j] == true && nums[j] >= i-j){can[i] = true;break;}}}return can[length-1];} };
优化:记录能到达的最远距离,时间复杂度只有o(n)
class Solution { public:bool canJump(vector<int>& nums) {int length = nums.size();if(length < 0)return false;int canarrive = 0;for(int i = 0;i <= canarrive && canarrive < length-1;i++){if(i + nums[i] > canarrive)canarrive = i + nums[i];}return canarrive >= length-1;} };
转载于:https://www.cnblogs.com/ymjyqsx/p/7468001.html
55.Jump Game相关推荐
- 【贪心 和 DP】LeetCode 55. Jump Game
LeetCode 55. Jump Game 貌似一直就没做几个贪心的题,是时候好好学习一个了.. 参考网址:http://www.cnblogs.com/grandyang/p/4371526.ht ...
- 【LeetCode】(55)Jump Game(Medium)
题目 Jump Game Total Accepted: 52275 Total Submissions: 194395My Submissions Question Solution Given ...
- 55. Jump Game
description: 看是否能跳到最后. Note: Example: Example 1:Input: [2,3,1,1,4] Output: true Explanation: Jump 1 ...
- 【贪心】LeetCode 55. Jump Game
LeetCode 45. Jump Game II 参考网址:http://www.cnblogs.com/grandyang/p/4373533.html Solution1: 贪心算法,这里贪婪并 ...
- 55. Jump Game 解题记录
题目描述: Given an array of non-negative integers, you are initially positioned at the first index of th ...
- LeetCode 55. Jump Game
题目描述 You are given an integer array nums. You are initially positioned at the array's first index, a ...
- leetcode 55. Jump Game | 55. 跳跃游戏(暴力递归->傻缓存->DP)
题目 https://leetcode.com/problems/jump-game/ 题解 又是经典套路,暴力递归->傻缓存->DP 没写草稿,直接看代码吧 class Solution ...
- 55. Jump Game(跳跃游戏)
题目链接:https://leetcode.com/problems/jump-game/ 此题的思路同Leetcode45,jumpGame2. Leetcode 45 就是用一个值来保存最大右边界 ...
- 55. Jump Game蹦蹦游戏Python Java
给定一个非负整数数组,您最初位于该数组的第一个索引处.数组中的每个元素代表该位置的最大跳转长度.确定您是否能够达到最后一个索引.类似于第45题 Input: nums = [2,3,1,1,4] Ou ...
最新文章
- LAMBDA表达式常用 (全)
- favicon支持的图片格式
- Enable trace in Resale Order application
- expressjs路由和Nodejs服务器端发送REST请求 - - ITeye博客
- python实现文件转数组
- 使用若依前后端分离下载需要授权的url文件
- SpringBoot注册组件之@Configuration@Bean注解作用及注意点
- 计算机功能自定义,电脑鼠标自定义按键设置方法
- 【C#】打印机ZPL指令,打印文本,中文,条码,图片
- CentOS7-Docker-DockerFile-05
- .NET开发邮件发送功能的全面教程(含邮件组件源码)
- 强网杯2019(高明的黑客强网先锋上单)
- stl文件用proe怎么打开_3dMax怎么导入proe的文件渲染?3dmax导入stl文件过程
- 大数据的主要学习内容有哪些?
- 项目管理之 项目阶段划分
- (Java)类的接口实验
- OpenCV C++录制视频录制与播放
- 计算机应用2010的答案,《计算机应用基础(Windows 7+Office 2010)》参考答案
- 联想e550笔记本怎么样_综合性能实测 全文总结_ThinkPad E550_笔记本评测-中关村在线...
- 数据结构(一)——链表与邻接表、栈与队列、KMP