-
Notifications
You must be signed in to change notification settings - Fork 1
/
44.cpp
executable file
·50 lines (50 loc) · 1.28 KB
/
44.cpp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class Solution {
public:
bool ifm;
string tmps,tmpp;
void dfs(int index1,int index2) {
if (index2 == tmpp.size() && index1 < tmps.size())
return;
if (index2 < tmpp.size() && index1 == tmps.size()){
ifm = true;
for (int i = index2; i<tmpp.size();i++)
if (tmpp[i] != '*'){
ifm = false;
break;
}
return;
}
if (index2 == tmpp.size() && index1 == tmps.size()){
ifm = true;
return;
}
if (tmpp[index2] != '*'){
if (tmpp[index2] == '?')
dfs(index1+1,index2+1);
if (ifm)
return;
if (tmpp[index2] != tmps[index1])
return;
else
dfs(index1+1,index2+1);
}else{
for (int i = index1; i <= tmps.size();i++){
dfs(i,index2+1);
if (ifm)
return;
}}
}
bool isMatch(string s, string p) {
if ((s.size() == 0) && (p == "*"))
return true;
ifm = false;
tmps = s;
tmpp = p;
dfs(0,0);
return ifm;
}
};