Skip to content

Instantly share code, notes, and snippets.

@unpluggedcoder
Created February 6, 2020 15:20
Show Gist options
  • Save unpluggedcoder/2d0c10c3fb596fd41eb5529ceec677c4 to your computer and use it in GitHub Desktop.
Save unpluggedcoder/2d0c10c3fb596fd41eb5529ceec677c4 to your computer and use it in GitHub Desktop.
Leetcode snippets
#![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