给定两个字符串S1和S2 s1包含从A到Z的字符,s2包含从A到z的字符以及* ?
*表示任何字符出现0次或者任意次数
?表示任何字符出现0次或者一次
我想any character应该表示A到Z的字符
Given two string S1 and S2. S1 contains from A-Z and S2 contains A-Z, * and ?
Where * means any character 0 or any number of times
Write a program to determine whether S2 matches S1
代码很简单,用的是递归的思路。纯拷贝过来的,没运行过。
boolean check(String s1, String s2){
if(s2.equals("*")) return true;
if(s1.equals(s2)) return true;
if(s2.charAt(0)=='?')
{
return check(s1.substring(1),s2.substring(1))||check(s1,s2.substring(1));
}
else if(s2.charAt(0)=='*')
{
for(int i=0;i<s1.length();i++)
{
if(check(s1.substring(i),s2.substring(1)) retun true;
}
return false;
}
else if(s1.charAt(0)!=s2.charAt(0)) return false;
return check(s1.substring(1),s2.substring(1));
}


被折叠的 条评论
为什么被折叠?



