Jump Game
来源:互联网 发布:数据库怎么设计 编辑:程序博客网 时间:2024/04/29 03:27
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
.
题目解析:
(1)设置一个jumpPos 表示从当前这个位置可以调到最后
(2)如果jumpPos为0,那就返回true。否则返回false。
#include <iostream>using namespace std;bool canJump(int A[], int n) {int jumpPos = n - 1;for(int i=n-2;i>=0;i--){if(A[i] >= (jumpPos-i) )jumpPos = i;}if(jumpPos == 0)return true;elsereturn false;}int main(void){int A[] = {2,0,0};int n = sizeof(A)/sizeof(int);cout << canJump(A,n) << endl;system("pause");return 0;}
0 0
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- Jump Game
- 【ThinkingInC++】56、函数中的引用
- 《Storm实时数据处理》学习笔记之二:使用Vagrant配置本地集群(下)
- oracle学习笔记二
- [SqlServer03]-数据库高可用性方案
- 【ThinkingInC++】57、位拷贝和初始化
- Jump Game
- 通过Sqoop实现Mysql / Oracle 与HDFS / Hbase互导数据
- android的文件操作。(未整理完成)
- OS—操作系统
- Java项目(2)——Java开发环境配置|JDK与JRE
- Precision power (高精度幂运算)(相乘的变体)
- hdoj 1084 What Is Your Grade?
- 冒泡排序总结
- 黑马程序员——OC语言初学