烧脑神题
public class Solution { public boolean isMatch(String s, String p) { // 反正我是想不出来 http://www.cnblogs.com/springfor/p/3893593.html if(p.length()==0) return s.length()==0; if(p.length()==1) return (s.length()==1 &&(p.charAt(0)==s.charAt(0)||p.charAt(0)==‘.‘)); if(p.charAt(1)!=‘*‘){ if(s.length()<1) return false; return (s.charAt(0)==p.charAt(0)||p.charAt(0)==‘.‘)&&(isMatch(s.substring(1), p.substring(1))); }else{ while(s.length()>0&&(p.charAt(0)==s.charAt(0)||p.charAt(0)==‘.‘)){ if(isMatch(s , p.substring(2))) return true; s = s.substring(1); // p= a*????; s = aaaaa???? } return isMatch(s, p.substring(2)); // p= b*?????, s = a???? } } }
时间: 2024-10-13 20:52:08