From 79a9c52fa923fc78074d88463449a8b7f95ca3ef Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 26 Dec 2017 01:33:40 +0800 Subject: update leetcode solution --- Computer_Science/leetcode/55-jump_game.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Computer_Science/leetcode/55-jump_game.c (limited to 'Computer_Science/leetcode/55-jump_game.c') 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; +} -- cgit v1.2.3