aboutsummaryrefslogtreecommitdiff
path: root/other/jump_game.rs
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-03-10 00:36:13 -0600
committerJack Sangdahl <[email protected]>2025-03-10 00:36:13 -0600
commit7c60dee83b436e8e8a667bf9f191beced8de4fc3 (patch)
treeeb7a24ee2067f92245c57bb118e85a1baf15df50 /other/jump_game.rs
parent5d7cdc215e4ba1ec4cbb24c084cccb5e5e641468 (diff)
downloadleetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.tar.gz
leetcode-7c60dee83b436e8e8a667bf9f191beced8de4fc3.zip
chore: move cpp and rust code to directory
Diffstat (limited to 'other/jump_game.rs')
-rw-r--r--other/jump_game.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/other/jump_game.rs b/other/jump_game.rs
new file mode 100644
index 0000000..e7f36b0
--- /dev/null
+++ b/other/jump_game.rs
@@ -0,0 +1,18 @@
+struct Solution;
+
+impl Solution {
+ pub fn can_jump(nums: Vec<i32>) -> bool {
+ let mut n = 1;
+ for i in (0..nums.len() - 1).rev() {
+ n = if nums[i] < n { n + 1 } else { 1 };
+ }
+ n == 1
+ }
+}
+
+fn main() {
+ let nums1 = vec![2,3,1,1,4];
+ let nums2 = vec![3,2,1,0,4];
+ println!("{}", Solution::can_jump(nums1));
+ println!("{}", Solution::can_jump(nums2));
+}