Wildcard Matching
来源:互联网 发布:linux 给程序root权限 编辑:程序博客网 时间:2024/06/06 03:04
11/1
这个难题一遍做出来了
public class Solution { public boolean isMatch(String s, String p) { int slen = s.length(), plen = p.length(); int ss = 0, pp = 0; int sc = -1, pc = -1; while(ss < slen){ if(pp < plen && p.charAt(pp) == '*'){ sc = ss; pc = pp; pp++; }else if(pp >= plen || (pp < plen && p.charAt(pp) != '?' && s.charAt(ss) != p.charAt(pp))){ if(sc < 0){ // nothing cached before return false; }else{ // restore to where previously cached ss = ++sc; pp = pc; } }else{ ss++; pp++; } } // note that it is okay if pp doesn't hit the end; just check if // only *'s remain for(; pp < plen; pp++){ char pchar = p.charAt(pp); if(pchar != '*') return false; } return true; }}
0 0
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- Wildcard Matching
- 各大公司经典算法面试题
- Oracle中的一些相关指令的使用
- Extjs4.2 tooltip 提示宽度问题解决
- 各种进制转换的原理
- c++中的 extern "C"
- Wildcard Matching
- [OSX使用技巧] 【教学】Mac OS X下终端的基本命令 [
- BestCoder Round #16
- 最全的 Web 开发项目检查清单
- 待到樱花漫天时
- [Android 性能优化系列]内存之基础篇--Android如何管理内存
- 韩顺平hibernate session工具类
- 关于Netica
- 谈数学学习