Created
February 6, 2020 15:20
-
-
Save unpluggedcoder/2d0c10c3fb596fd41eb5529ceec677c4 to your computer and use it in GitHub Desktop.
Leetcode snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(slice_patterns)] | |
impl Solution { | |
pub fn is_match(s: String, p: String) -> bool { | |
is_match(s.as_bytes(), p.as_bytes()) | |
} | |
} | |
fn is_match(s: &[u8], p: &[u8]) -> bool { | |
match (p, s) { | |
([x, b'*', subp..], [y, subs..]) if *x == b'.' || x == y => is_match(subs, p), | |
([_, b'*', subp..], _) => is_match(s, subp), | |
([x, subp..], [y, subs..]) if *x == b'.' || x == y => is_match(subs, subp), | |
([], s) => s.is_empty(), | |
_ => false, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment