请实现一个函数用来匹配包括'.'和'*'的正则表达式。模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(包含0次)。 在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串"aaa"与模式"a.a"和"ab*ac*a"匹配,但是与"aa.a"和"ab*a"均不匹配
示例1
输入
"aaa","a*a"
输出
true
加载中...
import java.util.*; public class Solution { public boolean match(char[] str, char[] pattern) { } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param str string字符串 * @param pattern string字符串 * @return bool布尔型 */ bool match(string str, string pattern) { // write code here } };
# -*- coding:utf-8 -*- class Solution: # s, pattern都是字符串 def match(self, s, pattern): # write code here
class Solution { public bool match(char[] str, char[] pattern) { // write code here } }
//s, pattern都是字符串 function match(s, pattern) { // write code here } module.exports = { match : match };
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @param pattern string字符串 * @return bool布尔型 */ func match( s string , pattern string ) bool { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param s string字符串 # @param pattern string字符串 # @return bool布尔型 # class Solution def match(s, pattern) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @param pattern string字符串 * @return bool布尔型 */ def match(s: String,pattern: String): Boolean = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @param pattern string字符串 * @return bool布尔型 */ fun match(s: String,pattern: String): Boolean { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @param pattern string字符串 * @return bool布尔型 */ public boolean match (String s, String pattern) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @param pattern string字符串 * @return bool布尔型 */ export function match(s: string, pattern: string): boolean { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @param pattern string字符串 * @return bool布尔型 */ func match ( _ s: String, _ pattern: String) -> Bool { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param s string字符串 * @param pattern string字符串 * @return bool布尔型 */ pub fn match(&self, s: String, pattern: String) -> bool { // write code here } }
"aaa","a*a"
true