aboutsummaryrefslogtreecommitdiff
path: root/Computer_Science/leetcode/55-jump_game.c
diff options
context:
space:
mode:
authorSteve Lee <me@xiangyangli.com>2017-12-26 01:33:40 +0800
committerSteve Lee <me@xiangyangli.com>2017-12-26 01:33:40 +0800
commit79a9c52fa923fc78074d88463449a8b7f95ca3ef (patch)
tree80c2b596a7c41124845771dca99abd364e89d4c4 /Computer_Science/leetcode/55-jump_game.c
parent2e0e0f39d49296f0ffb99aea533a527174521d61 (diff)
download42-79a9c52fa923fc78074d88463449a8b7f95ca3ef.tar.xz
42-79a9c52fa923fc78074d88463449a8b7f95ca3ef.zip
update leetcode solution
Diffstat (limited to 'Computer_Science/leetcode/55-jump_game.c')
-rw-r--r--Computer_Science/leetcode/55-jump_game.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/Computer_Science/leetcode/55-jump_game.c b/Computer_Science/leetcode/55-jump_game.c
new file mode 100644
index 0000000..cdf3ca7
--- /dev/null
+++ b/Computer_Science/leetcode/55-jump_game.c
@@ -0,0 +1,12 @@
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+bool canJump(int* nums, int numsSize) {
+ int reach;
+ int i;
+ for(i = 0, reach = 0; i < numsSize && i <= reach; i++) {
+ reach = MAX(i + nums[i], reach);
+ if(reach >= numsSize - 1)
+ return true;
+ }
+
+ return false;
+}