-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10.cpp
More file actions
28 lines (27 loc) · 743 Bytes
/
10.cpp
File metadata and controls
28 lines (27 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//
// 10.cpp
// leetcode
//
// Created by R Z on 2018/1/29.
// Copyright © 2018年 R Z. All rights reserved.
//
#include <stdio.h>
#include <string>
using namespace std;
class Solution {
public:
bool isMatch(string s, string p) {
if(s[0]=='\0' && p[0]=='\0') return true;
if(s[0]!='\0' && p[0]=='\0') return false;
if(p[1]=='*'){
if(s[0]==p[0] || (s[0]!='\0'&&p[0]=='.')){
return isMatch(s.substr(1), p)||isMatch(s,p.substr(2));
}else return isMatch(s,p.substr(2));
}else{
if(s[0]==p[0] || (s[0]!='\0' && p[0]=='.')){
return isMatch(s.substr(1), p.substr(1));
}else return false;
}
return false;
}
};