diff --git a/LeetCode/Jump_Game.cpp b/LeetCode/Jump_Game.cpp new file mode 100644 index 0000000..7975896 --- /dev/null +++ b/LeetCode/Jump_Game.cpp @@ -0,0 +1,20 @@ +class Solution { +public: + bool canJump(vector& nums) { + int maxReach = 0; + + for (int i = 0; i < nums.size(); i++) { + if (maxReach < i) { + return false; + } + + maxReach = max(maxReach, i + nums[i]); + + if (maxReach >= nums.size() - 1) { + return true; + } + } + + return false; + } +}; \ No newline at end of file