[Leetcode] wildcard matching

Source: Internet
Author: User

Implement wildcard pattern matching with support‘?‘And‘*‘.

'? 'Matches any single character. '*' matches any sequence of characters (including the empty sequence). The matching shocould coverEntireInput string (not partial ). the function prototype shoshould be: bool ismatch (const char * s, const char * P) some examples: ismatch ("AA", "A") → falseismatch ("AA ", "AA") → trueismatch ("AAA", "AA") → falseismatch ("AA", "*") → trueismatch ("AA", "*") → trueismatch ("AB ","? * ") → Trueismatch (" AAB "," C * a * B ") → false

Solution:
Greedy Algorithm:
Http://blog.unieagle.net/2012/11/07/leetcode%E9%A2%98%E7%9B% AE %EF%BC%9Awildcard-matching/

You only need to separate P into substrings without '*' based on the continuous. Then match the strings in S, but you need to take special care of the first and last two substrings:
1. For P whose start is not '*', the first substring must start from S [0 ].
2. For P whose end is not '*', the last substring must match with the tail of S.


[Leetcode] wildcard matching

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.