-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREM
More file actions
31 lines (29 loc) · 862 Bytes
/
REM
File metadata and controls
31 lines (29 loc) · 862 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package 无重复字符的最长字符串;
/**
*
* @author junye.mao
*/
public class REM {
public boolean isMatch(String s, String p) {
if(s==null || p==null)return false;
char[] sc=s.toCharArray();
char[] pc=p.toCharArray();
return dp(sc,pc,0,0);
}
boolean dp(char[] s,char[] p,int i,int j){
int n=s.length;
int m=p.length;
if(j>=m) return i==n;
//判断第一个字符匹配结果
boolean j_match=i<n &&(s[i]==p[j] || p[j]=='.');
if(j+1<m && p[j+1]=='*'){
return dp(s,p,i,j+2)||(j_match &&dp(s,p,i+1,j));
}
return j_match && dp(s,p,i+1,j+1);
}
}