Leetcode 44. Wildcard Matching
来源:互联网 发布:网络人士周小平 编辑:程序博客网 时间:2024/06/05 22:47
题目:
'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The function prototype should be:bool isMatch(const char *s, const char *p)Some examples:isMatch("aa","a") → falseisMatch("aa","aa") → trueisMatch("aaa","aa") → falseisMatch("aa", "*") → trueisMatch("aa", "a*") → trueisMatch("ab", "?*") → trueisMatch("aab", "c*a*b") → false
思路:
代码:
public class Solution { public boolean isMatch(String s, String p) { char[] chars = s.toCharArray(); char[] charp = p.toCharArray(); int ss = -1,pp = -1; int sIndex = 0,pIndex = 0; while(sIndex<chars.length){ if(pIndex == charp.length){//false,回溯 if(pp == -1) return false; pIndex = pp+1; sIndex = ss++; } else if(charp[pIndex] == '?' || chars[sIndex] == charp[pIndex]){//相同 pIndex++;sIndex++; }else if(charp[pIndex] == '*'){ pp = pIndex;ss = sIndex;pIndex = pp+1; }else{ if(pp == -1) return false; pIndex = pp+1;sIndex = ss++; } } while(pIndex<charp.length){ if(charp[pIndex] != '*') break; pIndex++; } return pIndex == charp.length; }}
0 0
- LeetCode --- 44. Wildcard Matching
- [Leetcode] 44. Wildcard Matching
- Leetcode 44. Wildcard Matching
- leetcode 44. Wildcard Matching
- Leetcode 44. Wildcard Matching
- Leetcode:44. Wildcard Matching
- LeetCode 44. Wildcard Matching
- leetcode.44. Wildcard Matching
- LeetCode 44. Wildcard Matching
- Leetcode-44. Wildcard Matching
- [LeetCode] 44. Wildcard Matching
- [leetcode] 44. Wildcard Matching
- [LeetCode]--44. Wildcard Matching
- LeetCode 44. Wildcard Matching
- leetcode 44. Wildcard Matching
- LeetCode 44. Wildcard Matching
- 44. Wildcard Matching -- LeetCode
- LeetCode 44. Wildcard Matching
- Struts2(五)——核心拦截器
- Lambda expressions are not supported at this language level
- Binary Tree Level Order Traversal 解题报告
- Libusb开发教程<二> API介绍与使用
- wc命令
- Leetcode 44. Wildcard Matching
- React/React Native 的ES5 ES6写法对照表2
- python input 提示 no encoding declared
- 【poj1456 】supermarket
- idea添加jar包时启动tomcat项目时显示jar包找不到
- Python练习3-XML-RPC实现简单的P2P文件共享
- JMS
- autojump——一步到位
- windows下安装composer,纯手工,绝对有效