博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode 44:Wildcard Matching
阅读量:4151 次
发布时间:2019-05-25

本文共 972 字,大约阅读时间需要 3 分钟。

Implement wildcard pattern matching with support for '?' and '*'.

'?' 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

题目要求实现模糊匹配,代码如下:

class Solution {public:    bool isMatch(const char *s, const char *p) {    	bool isStar = false;		const char* s1, *p1;		while(*s && (*p || isStar)){			if((*s==*p) || (*p=='?')){				s++; p++;			}else if(*p == '*'){				isStar = true;				p++;				if(*p=='\0') return true;				s1 = s;				p1 = p;			}else{				if(!isStar) return false;				p =p1;				s = ++s1;			}		}		if(*s=='\0'){			while(*p=='*')p++;			if(*p=='\0') return true;		}		return false;    }};

转载地址:http://tbxti.baihongyu.com/

你可能感兴趣的文章
前阿里手淘前端负责人@winter:前端人如何保持竞争力?
查看>>
【JavaScript 教程】面向对象编程——实例对象与 new 命令
查看>>
我在网易做了6年前端,想给求职者4条建议
查看>>
SQL1015N The database is in an inconsistent state. SQLSTATE=55025
查看>>
RQP-DEF-0177
查看>>
MySQL字段类型的选择与MySQL的查询效率
查看>>
Java的Properties配置文件用法【续】
查看>>
JAVA操作properties文件的代码实例
查看>>
java杂记
查看>>
RunTime.getRuntime().exec()
查看>>
Oracle 分组排序函数
查看>>
删除weblogic 域
查看>>
VMware Workstation 14中文破解版下载(附密钥)(笔记)
查看>>
日志框架学习
查看>>
日志框架学习2
查看>>
SVN-无法查看log,提示Want to go offline,时间显示1970问题,error主要是 url中 有一层的中文进行了2次encode
查看>>
NGINX
查看>>
Qt文件夹选择对话框
查看>>
DeepLearning tutorial(5)CNN卷积神经网络应用于人脸识别(详细流程+代码实现)
查看>>
DeepLearning tutorial(6)易用的深度学习框架Keras简介
查看>>