[LeetCode] 44。ワイルドカードマッチングマッチワイルドカード
44 Wildcard Matching Match Wild Card
'?'
をサポートするワイルドカードパターンマッチングを実装しますおよび'*'
。
public class WildcardMatching { public boolean isMatch(String s, String p) { int i = 0 int j = 0 int star = -1 int mark = -1 while (i ワイルドカードマッチング、および10.正規表現マッチングなど。 「?」文字に一致します。「*」は、空を含む任意の文字シーケンスに一致します。そこに貪欲貪欲、動的計画法DPソリューションがあります。
Java:貪欲、反復
class Solution: def isMatch(self, s, p): p_ptr, s_ptr, last_s_ptr, last_p_ptr = 0, 0, -1, -1 while s_ptr Python:欲張り、反復
'?' Matches any single character. '*' Matches any sequence of characters (including the empty sequence). 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') → false isMatch('aa','aa') → true isMatch('aaa','aa') → false isMatch('aa', '*') → true isMatch('aa', 'a*') → true isMatch('ab', '?*') → true isMatch('aab', 'c*a*b') → false
同様のトピック: