20240811 Finished
This commit is contained in:
		| @@ -200,4 +200,5 @@ mod p139_word_break; | |||||||
| mod p300_longest_increasing_subsequence; | mod p300_longest_increasing_subsequence; | ||||||
| mod p120_triangle; | mod p120_triangle; | ||||||
| mod p64_minimum_path_sum; | mod p64_minimum_path_sum; | ||||||
| mod p63_unique_paths_ii; | mod p63_unique_paths_ii; | ||||||
|  | mod p97_interleaving_string; | ||||||
							
								
								
									
										48
									
								
								src/problem/p97_interleaving_string.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/problem/p97_interleaving_string.rs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | |||||||
|  | /** | ||||||
|  |  * [97] Interleaving String | ||||||
|  |  */ | ||||||
|  | pub struct Solution {} | ||||||
|  |  | ||||||
|  |  | ||||||
|  | // submission codes start here | ||||||
|  |  | ||||||
|  | impl Solution { | ||||||
|  |     pub fn is_interleave(s1: String, s2: String, s3: String) -> bool { | ||||||
|  |         let (s1, s2, s3): (Vec<char>, Vec<char>, Vec<char>) = (s1.chars().collect(), s2.chars().collect(), s3.chars().collect()); | ||||||
|  |         let (n, m, t) = (s1.len(), s2.len(), s3.len()); | ||||||
|  |          | ||||||
|  |         if n + m != t { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         let mut dp = vec![false; m + 1]; | ||||||
|  |         dp[0] = true; | ||||||
|  |          | ||||||
|  |         for i in 0..=n { | ||||||
|  |             for j in 0..=m { | ||||||
|  |                 let p = i + j - 1; | ||||||
|  |                  | ||||||
|  |                 if i != 0 { | ||||||
|  |                     dp[j] &= s1[i - 1] == s3[p]; | ||||||
|  |                 } | ||||||
|  |                  | ||||||
|  |                 if j != 0 { | ||||||
|  |                     dp[j] |= dp[j - 1] && s2[j - 1] == s3[p]; | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |          | ||||||
|  |         dp[m] | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // submission codes end | ||||||
|  |  | ||||||
|  | #[cfg(test)] | ||||||
|  | mod tests { | ||||||
|  |     use super::*; | ||||||
|  |  | ||||||
|  |     #[test] | ||||||
|  |     fn test_97() { | ||||||
|  |     } | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user