-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path97.交错字符串.rs
32 lines (31 loc) · 836 Bytes
/
97.交错字符串.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
* @lc app=leetcode.cn id=97 lang=rust
*
* [97] 交错字符串
*/
// @lc code=start
impl Solution {
pub fn is_interleave(s1: String, s2: String, s3: String) -> bool {
let m = s1.len();
let n = s2.len();
if m + n != s3.len() {
return false;
}
let mut f: Vec<bool> = vec![false; n + 1];
f[0] = true;
for i in 0..=m {
for j in 0..=n {
let p = i + j - 1;
if i > 0 {
f[j] &= s3.chars().nth(p).unwrap() == s1.chars().nth(i - 1).unwrap();
}
if j > 0 {
f[j] |=
(f[j - 1] && s3.chars().nth(p).unwrap() == s2.chars().nth(j - 1).unwrap());
}
}
}
return f[n];
}
}
// @lc code=end