Skip to content

Commit 71fe678

Browse files
committed
src/bin/is-subsequence.rs
1 parent e5b7b38 commit 71fe678

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/bin/is-subsequence.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
fn main() {}
2+
3+
struct Solution;
4+
5+
impl Solution {
6+
pub fn is_subsequence(s: String, t: String) -> bool {
7+
let (mut i, mut j) = (0, 0); // i: s'index, j: t'index
8+
let (s, t) = (s.as_bytes(), t.as_bytes());
9+
loop {
10+
if i == s.len() {
11+
return true;
12+
}
13+
if j == t.len() {
14+
break;
15+
}
16+
17+
if s[i] == t[j] {
18+
i += 1;
19+
}
20+
j += 1;
21+
}
22+
23+
return false;
24+
}
25+
}

0 commit comments

Comments
 (0)