From 5ea4ec6829730a2cba0c8fec7009e0c3b82d238c Mon Sep 17 00:00:00 2001 From: cezarbbb <105843128+cezarbbb@users.noreply.github.com> Date: Wed, 27 Jul 2022 16:20:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200055.=E8=B7=B3=E8=B7=83?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=20Rust=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 0055.跳跃游戏 Rust版本 --- problems/0055.跳跃游戏.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/problems/0055.跳跃游戏.md b/problems/0055.跳跃游戏.md index e7c4f5a2..394117ee 100644 --- a/problems/0055.跳跃游戏.md +++ b/problems/0055.跳跃游戏.md @@ -154,6 +154,26 @@ var canJump = function(nums) { }; ``` +### Rust + +```Rust +impl Solution { + fn max(a: usize, b: usize) -> usize { + if a > b { a } else { b } + } + pub fn can_jump(nums: Vec) -> bool { + let mut cover = 0; + if (nums.len() == 1) { return true; } + let mut i = 0; + while i <= cover { + cover = Self::max(i + nums[i] as usize, cover); + if cover >= nums.len() - 1 { return true; } + i += 1; + } + false + } +} +``` ### C ```c