From e07011a229349d55028d3439141bfe91f5ac09bf Mon Sep 17 00:00:00 2001 From: SquidSpirit Date: Tue, 4 Mar 2025 00:42:36 +0800 Subject: [PATCH] feat: 55_jump_game --- 55_jump_game/main.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 55_jump_game/main.cpp diff --git a/55_jump_game/main.cpp b/55_jump_game/main.cpp new file mode 100644 index 0000000..42f91ce --- /dev/null +++ b/55_jump_game/main.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; + +class Solution { + public: + bool canJump(vector& nums) { + int farthest = 0; + + for (int i = 0; i < nums.size() && i <= farthest; i++) { + farthest = max(farthest, i + nums[i]); + if (farthest >= nums.size() - 1) return true; + } + + return false; + } +};