From 6d43ed98e44d6645203f8ecba70cf0a3a0eb0053 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 5 Dec 2024 03:27:08 +0000 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EC=8A=88=20#446=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=86=94=EB=A3=A8=EC=85=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LeetCode/Jump_Game.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 LeetCode/Jump_Game.cpp 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