diff options
Diffstat (limited to 'other/jump_game.cpp')
-rw-r--r-- | other/jump_game.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/other/jump_game.cpp b/other/jump_game.cpp new file mode 100644 index 0000000..153d9aa --- /dev/null +++ b/other/jump_game.cpp @@ -0,0 +1,24 @@ +#include "leetcode.h" + +class Solution { +public: + bool canJump(vector<int> &nums) { + int minJump = 0; + for (int i = nums.size() - 2; i >= 0; i--) { + minJump++; + if (nums[i] >= minJump) + minJump = 0; + } + if (minJump == 0) + return true; + else + return false; + } +}; + +int main() { + Solution obj; + vector<int> nums1 = {2, 3, 1, 1, 4}, nums2 = {3, 2, 1, 0, 4}; + testBool(obj.canJump(nums1)); // true + testBool(obj.canJump(nums2)); // false +} |