设为首页 加入收藏

TOP

Regular Expression Matching
2015-07-20 17:31:33 来源: 作者: 【 】 浏览:2
Tags:Regular Expression Matching

Implement regular expression matching with support for '.' and '*'.

'.' Matches any single character.
'*' Matches zero or more of the preceding element.

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") → false
isMatch("aa","aa") → true
isMatch("aaa","aa") → false
isMatch("aa", "a*") → true
isMatch("aa", ".*") → true
isMatch("ab", ".*") → true
isMatch("aab", "c*a*b") → true

答案

public class Solution {
    public boolean match(char s,char p)
    {
        return s==p||p=='.';
    }
    public boolean isMatch(String s, String p)
    {
        int sLen = s.length();
        int pLen = p.length();
        int i;
        int j;
        int k;
        boolean[][] match = new boolean[sLen+1][pLen+1];
        match[0][0]=true;
        for(i=0;i
  
   

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇BZOJ 1040 ZJOI 2008 骑士 基环树.. 下一篇hduoj-----(2896)病毒侵袭(ac自动..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·在 Redis 中如何查看 (2025-12-26 03:19:03)
·Redis在实际应用中, (2025-12-26 03:19:01)
·Redis配置中`require (2025-12-26 03:18:58)
·Asus Armoury Crate (2025-12-26 02:52:33)
·WindowsFX (LinuxFX) (2025-12-26 02:52:30)