[leetcode algorithms]題目10
10. Regular Expression Matching
Implement regular expression matching with support for .
and *
.
. Matches any single character.* Matches zero or more of the preceding element.The matching should cover the entire input string (not partial).The function prototype should be:bool isMatch(const char *s, const char *p)Some examples:isMatch("aa","a") → falseisMatch("aa","aa") → trueisMatch("aaa","aa") → falseisMatch("aa", "a*") → trueisMatch("aa", ".*") → trueisMatch("ab", ".*") → trueisMatch("aab", "c*a*b") → true
自己寫的代碼:
非常無恥地使用了正則表達式[捂臉]。運行時間155 ms
import reclass Solution: def isMatch(self, s, p): return True if re.compile(^ + p + $).match(s) else False
推薦閱讀:
※[leetcode algorithms]題目20
※《C++ Primer》讀書筆記-第九章 04 vector對象增長
※010 Regular Expression Matching[H]
※[leetcode algorithms]題目5
TAG:LeetCode |