-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwildcard.java
More file actions
33 lines (31 loc) · 901 Bytes
/
wildcard.java
File metadata and controls
33 lines (31 loc) · 901 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
29
30
31
32
33
public class Solution {
public boolean isMatch(String s, String p) {
// Start typing your Java solution below
// DO NOT write main() function
if(s.equals("")) {
if(p.equals("")||p.equals("*"))
return true;
return false;
}
if(p.equals(""))
return false;
String ss="",pp="";
int j=0;
while(p.charAt(j)=='*') j++;
if(p.charAt(0)=='*') {
int i;
for(i=0;i<=s.length();i++) {
if(isMatch(s.substring(i),p.substring(j))) return true;
}
return false;
}
else {
if(p.charAt(0)!='?')
if(s.charAt(0)!=p.charAt(0))
return false;
ss=s.substring(1);
pp=p.substring(1);
}
return isMatch(ss,pp);
}
}