Skip to content

Commit 6ec4172

Browse files
authored
Merge pull request neetcode-gh#1292 from zim0369/392-Is-Subsequence
Create 392-Is-Subsequence.rs
2 parents 8ac9c00 + b7cfd4f commit 6ec4172

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use std::cmp::max;
2+
3+
impl Solution {
4+
pub fn replace_elements(arr: Vec<i32>) -> Vec<i32> {
5+
let length = arr.len();
6+
let mut ans: Vec<i32> = vec![-1; length];
7+
for i in (1..=(length - 1)).rev() {
8+
ans[i - 1] = max(arr[i], ans[i]);
9+
}
10+
ans
11+
}
12+
}

rust/392-Is-Subsequence.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
impl Solution {
2+
pub fn is_subsequence(s: String, t: String) -> bool {
3+
let s: Vec<char> = s.chars().collect();
4+
let t: Vec<char> = t.chars().collect();
5+
let mut l = 0;
6+
let mut r = 0;
7+
while l < s.len() && r < t.len() {
8+
if s[l] == t[r] {
9+
l += 1;
10+
r += 1;
11+
} else {
12+
r += 1;
13+
}
14+
}
15+
l == s.len()
16+
}
17+
}

0 commit comments

Comments
 (0)