Leetcode's regular Expression Matching (31)

Source: Internet
Author: User

The matching of regular expressions is still very difficult. Depending on whether the next character is * divided into two situations, there are a number of scenarios to consider.

BOOLIsMatch (Const Char*s,Const Char*p) {if(*p = =' /')return*s = =' /'; //if the next is not * (* can represent the number of previous characters)//either the current character matches, or the., cannot be skipped          if(* (P +1) !='*')          {              if(*s = = *p | | (*p = ='.'&& *s! =' /'))                  returnIsMatch (S +1, p +1); Else                  return false; }          Else          {              //if it is *, the current character match | | has one for. //because the back is *, even if not exactly match is OK, skip can               while(*p = = *s | | (*p = ='.'&& *s! =' /'))              {                  if(IsMatch (s, p +2))                      return true; S++; }              returnIsMatch (s, p +2); }      }
View Code

Leetcode's regular Expression Matching (31)

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.