From 42c1ae903c44b32f85a47eff37dddf3046afafc0 Mon Sep 17 00:00:00 2001 From: Harvey Date: Sat, 31 Aug 2024 20:29:23 +0800 Subject: [PATCH] [python[js]]00010.regular-expression-matching --- .../00010.regular-expression-matching/10.js | 13 +++++++++++++ .../00010.regular-expression-matching/10.py | 12 ++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/leetcode/00010.regular-expression-matching/10.js create mode 100644 src/leetcode/00010.regular-expression-matching/10.py diff --git a/src/leetcode/00010.regular-expression-matching/10.js b/src/leetcode/00010.regular-expression-matching/10.js new file mode 100644 index 0000000..05b3462 --- /dev/null +++ b/src/leetcode/00010.regular-expression-matching/10.js @@ -0,0 +1,13 @@ +/** + * @param {string} s + * @param {string} p + * @return {boolean} + */ +var isMatch = function (s, p) { + const reg = new RegExp(`^${p}$`); + return reg.test(s); +}; + +console.log(isMatch('aa', 'a')); +console.log(isMatch('aa', 'a*')); +console.log(isMatch('ab', '.*')); diff --git a/src/leetcode/00010.regular-expression-matching/10.py b/src/leetcode/00010.regular-expression-matching/10.py new file mode 100644 index 0000000..689021e --- /dev/null +++ b/src/leetcode/00010.regular-expression-matching/10.py @@ -0,0 +1,12 @@ +import re + + +class Solution: + def isMatch(self, s: str, p: str) -> bool: + + return False if re.match(f"^{p}$", s) == None else True + + +if __name__ == "__main__": + print(Solution().isMatch("aa", "a")) + print(Solution().isMatch("aa", "a*"))