# Leetcode 55. Jump Game ###### tags: `Leetcode(C++)` 題目 : https://leetcode.com/problems/jump-game/ 。 想法 : 更新能夠前往的最遠距離。 時間複雜度 : O(n)。 程式碼 : ``` class Solution { public: bool canJump(vector<int>& nums) { int l=nums.size(),now=nums[0]; for(int i=1 ; i<l ; i++){ if(i<=now){ now=max(now,i+nums[i]); } } if(now >= l-1) return true; return false; } }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up