010Regular Expression Matching__leetcode

Source: Internet
Author: User

'.' 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") →false
ismatch ("AA", "AA") →true
IsMatch ("AAA", "AA") →false IsMatch (
"AA", "A *") →true ismatch
("AA", ". *") →true
ismatch ("AB", ". *") →true
ismatch ("AaB", "C*a*b") →true
This regular expression match, I set the IF statement according to different conditions, at the time of submission, because the. * Matching problem did not pass, now first put the code, and then modify

BOOL IsMatch (char* s,char* p) {
    int i=0,j=0;
    if (p[i]!= '. ') &&p[i]!=s[j]) {return
    	false;
    }
    i++;
    j + +;
	while (s[j]!= ' &&p[i]!= ') {
		if (p[i]== '. ') P[i]==s[j]) {
			i++;
			j + +;
		} else if (p[i]== ' * ') {
			if (p[i-1]== '. ') {return
				true;
			} else if (p[i-1]== ' * ') {
				//
			}else{
				if (S[j]==p[i]) {
					j + +;
					while (S[j]==s[j-1]) {
						j + +;
					}
				}
				i++
			}
		} else{return
			false;
		}
	if (s[j]== ' ") {return
		true;
	} else{return
		false;
	} 	









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.