20240425 Finished
This commit is contained in:
parent
7dfbb99e64
commit
d27f640226
|
@ -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;
|
40
src/problem/p392_is_subsequence.rs
Normal file
40
src/problem/p392_is_subsequence.rs
Normal 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()));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user