当前位置:网站首页>Leetcode 44 Wildcard matching (2022.02.13)
Leetcode 44 Wildcard matching (2022.02.13)
2022-07-06 00:33:00 【ChaoYue_ miku】
Given a string (s) And a character pattern § , Implement a support ‘?’ and ‘*’ The wildcard matches .
‘?’ It can match any single character .
‘*’ Can match any string ( Include empty string ).
Only when two strings match exactly can the match be successful .
explain :
s May is empty , And contains only from a-z Lowercase letters of .
p May is empty , And contains only from a-z Lowercase letters of , As well as the character ? and *.
Example 1:
Input :
s = “aa”
p = “a”
Output : false
explain : “a” Can't match “aa” Whole string .
Example 2:
Input :
s = “aa”
p = ""
Output : true
explain : '’ Can match any string .
Example 3:
Input :
s = “cb”
p = “?a”
Output : false
explain : ‘?’ Can match ‘c’, But the second one ‘a’ Can't match ‘b’.
Example 4:
Input :
s = “adceb”
p = “ab”
Output : true
explain : first ‘’ Can match an empty string , the second '’ Can match string “dce”.
Example 5:
Input :
s = “acdcb”
p = “a*c?b”
Output : false
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/wildcard-matching
Method 1 : Dynamic programming
C++ Submission :
class Solution {
public:
bool isMatch(string s, string p) {
int m = s.size();
int n = p.size();
vector<vector<int>> dp(m + 1, vector<int>(n + 1));
dp[0][0] = true;
for (int i = 1; i <= n; ++i) {
if (p[i - 1] == '*') {
dp[0][i] = true;
}else {
break;
}
}
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
if (p[j - 1] == '*') {
dp[i][j] = dp[i][j - 1] | dp[i - 1][j];
}else if (p[j - 1] == '?' || s[i - 1] == p[j - 1]) {
dp[i][j] = dp[i - 1][j - 1];
}
}
}
return dp[m][n];
}
};
边栏推荐
- 2022.7.5-----leetcode. seven hundred and twenty-nine
- 数据分析思维分析方法和业务知识——分析方法(三)
- Global and Chinese market of water heater expansion tank 2022-2028: Research Report on technology, participants, trends, market size and share
- Spark SQL空值Null,NaN判断和处理
- Spark DF增加一列
- Global and Chinese markets for pressure and temperature sensors 2022-2028: Research Report on technology, participants, trends, market size and share
- How to use the flutter framework to develop and run small programs
- Room cannot create an SQLite connection to verify the queries
- How to solve the problems caused by the import process of ecology9.0
- Codeforces round 804 (Div. 2) [competition record]
猜你喜欢

How to solve the problems caused by the import process of ecology9.0

Tools to improve work efficiency: the idea of SQL batch generation tools

XML Configuration File

免费的聊天机器人API

Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?

Hudi of data Lake (2): Hudi compilation

多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
![[designmode] Decorator Pattern](/img/65/457e0287383d0ca9a28703a63b4e1a.png)
[designmode] Decorator Pattern

Start from the bottom structure and learn the introduction of fpga---fifo IP core and its key parameters

The relationship between FPGA internal hardware structure and code
随机推荐
常用API类及异常体系
MySql——CRUD
《强化学习周刊》第52期:Depth-CUPRL、DistSPECTRL & Double Deep Q-Network
Atcoder beginer contest 254 [VP record]
Single source shortest path exercise (I)
Data analysis thinking analysis methods and business knowledge - analysis methods (III)
建立时间和保持时间的模型分析
How to solve the problems caused by the import process of ecology9.0
[simple implementation of file IO]
notepad++正則錶達式替換字符串
Pointer - character pointer
7.5 simulation summary
免费的聊天机器人API
KDD 2022 | 脑电AI助力癫痫疾病诊断
Common API classes and exception systems
Arduino六足机器人
LeetCode 6004. Get operands of 0
数据分析思维分析方法和业务知识——分析方法(三)
Leetcode:20220213 week race (less bugs, top 10% 555)
Ffmpeg captures RTSP images for image analysis