From 6fb61ead0b5d723775958827e4d75a7199aecfe6 Mon Sep 17 00:00:00 2001 From: roylx <73628821+roylx@users.noreply.github.com> Date: Tue, 15 Nov 2022 11:01:24 -0700 Subject: [PATCH] =?UTF-8?q?Update=200055.=E8=B7=B3=E8=B7=83=E6=B8=B8?= =?UTF-8?q?=E6=88=8F.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加Python for循环版 --- problems/0055.跳跃游戏.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/problems/0055.跳跃游戏.md b/problems/0055.跳跃游戏.md index 23357f21..0ed03b07 100644 --- a/problems/0055.跳跃游戏.md +++ b/problems/0055.跳跃游戏.md @@ -119,6 +119,18 @@ class Solution: return False ``` +```python +## for循环 +class Solution: + def canJump(self, nums: List[int]) -> bool: + cover = 0 + if len(nums) == 1: return True + for i in range(len(nums)): + cover = max(i + nums[i], cover) + if cover >= len(nums) - 1: return True + return False +``` + ### Go ```Go func canJUmp(nums []int) bool {