20240425 Finished

This commit is contained in:
jackfiled 2024-04-25 10:02:32 +08:00
parent 7dfbb99e64
commit d27f640226
2 changed files with 42 additions and 1 deletions

View File

@ -111,4 +111,5 @@ mod p58_length_of_last_word;
mod p151_reverse_words_in_a_string;
mod p28_find_the_index_of_the_first_occurrence_in_a_string;
mod p68_text_justification;
mod p125_valid_palindrome;
mod p125_valid_palindrome;
mod p392_is_subsequence;

View File

@ -0,0 +1,40 @@
/**
* [392] Is Subsequence
*/
pub struct Solution {}
// submission codes start here
impl Solution {
pub fn is_subsequence(s: String, t: String) -> bool {
let t : Vec<char> = t.chars().collect();
let mut pos = 0;
for c in s.chars() {
while pos < t.len() && t[pos] != c {
pos += 1;
}
if pos >= t.len() {
return false;
}
pos += 1;
}
true
}
}
// submission codes end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_392() {
assert!(Solution::is_subsequence("abc".to_owned(), "ahbgdc".to_owned()));
}
}