[LeetCode]-010-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

题目:正则表达式匹配

 1 public class Solution{
 2     public boolean isMatch(String s, String p) {
 3         Pattern pattern = Pattern.compile(p);
 4         Matcher matcher = pattern.matcher(s);
 5         return matcher.matches();
 6     }
 7
 8     public static void main(String[] args){
 9         String param1 = "aa",param2 = ".*";
10         if(args.length==2){
11             param1 = args[0];
12             param2 = args[1];
13         }
14         Solution solution = new Solution();
15         boolean res = solution.isMatch(param1,param2);
16         System.out.println(res);
17     }
18 }
时间: 2024-07-30 10:18:11

[LeetCode]-010-Regular_Expression_Matching的相关文章

[LeetCode] 010. Regular Expression Matching (Hard) (C++/Java/Python)

索引:[LeetCode] Leetcode 题解索引 (C++/Java/Python/Sql) Github: https://github.com/illuz/leetcode 010.Regular_Expression_Matching (Hard) 链接: 题目:https://oj.leetcode.com/problems/regular-expression-matching/ 代码(github):https://github.com/illuz/leetcode 题意: 给

LeetCode 010 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 shou

LeetCode——010 Regular Expression Matching

title: LeetCode--010 Regular Expression Matching author: zzw top: false toc: true mathjax: false email: [email protected] date: 2020-02-19 22:05:32 updated: 2020-02-19 22:05:32 img: summary: categories: LeetCode tags: 字符匹配 --- Description Given an in

Java for LeetCode 010 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

LeetCode 010 Regular Expression Matching - Java

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

leetcode python 010

#实现正则表达式匹配并支持'.'和'*'.#''匹配任何单个字符.#'*'匹配前面元素的零个或多个.#匹配应覆盖整个输入字符串(非部分).##Some examples:##isMatch("aa","a") → false##isMatch("aa","aa") → true##isMatch("aaa","aa") → false##isMatch("aa", &

LeetCode题解 #8 String to Integer (atoi)

又是一道恶心的简单题. 一开始没想到这么多情况的,幸好LeetCode是个很人性化的oj,能让你知道你在哪个case上错了,否则一辈子都过不了. 考虑不周到只能一个个补了. 列举一下恶心的case //" 010" //" +004500" //" -0012a42" //"2147483648" //" b11228552307" //"18446744073709551617" //

LeetCode:Gray Code

1.题目名称 Gray Code(格雷码) 2.题目地址 https://leetcode.com/problems/gray-code/ 3.题目内容 英文: The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the

leetcode第一刷_Gray Code

说到格雷码,应该没人不知道,具体它有什么用,我还真不是很清楚,我室友应该是专家.生成的规律不是很明显,之前看到帖子讲的,这会儿找找不到了.. 思想是这样的,如果有n位,在第2^(n-1)个编码下面画一条水平线的话,你会发现除了第一位之外,其他位都是关于这条线对称的,如下,以三位格雷码举例: 000 001 011 010 --------------------- 110 111 101 100 很神奇吧,我以前是不知道这个规律的.从一开始的一位格雷码,0,1,开始,每次对称的在上一个前面添加上

LeetCode解题思路:476. Number Complement

Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. Note: The given integer is guaranteed to fit within the range of a 32-bit signed integer. You could assume no leading ze