[leetcode] 1023. Camelcase Matching
Description
A query word matches a given pattern if we can insert lowercase letters to the pattern word so that it equals the query. (We may insert each character at any position, and may insert 0 characters.)
Given a list of queries, and a pattern, return an answer list of booleans, where answer[i] is true if and only if queries[i] matches the pattern.
Example 1:
Input: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FB"
Output: [true,false,true,true,false]
Explanation:
"FooBar" can be generated like this "F" + "oo" + "B" + "ar".
"FootBall" can be generated like this "F" + "oot" + "B" + "all".
"FrameBuffer" can be generated like this "F" + "rame" + "B" + "uffer".
Example 2:
Input: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBa"
Output: [true,false,true,false,false]
Explanation:
"FooBar" can be generated like this "Fo" + "o" + "Ba" + "r".
"FootBall" can be generated like this "Fo" + "ot" + "Ba" + "ll".
Example 3:
Input: queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FoBaT"
Output: [false,true,false,false,false]
Explanation:
"FooBarTest" can be generated like this "Fo" + "o" + "Ba" + "r" + "T" + "est".
Note:
- 1 <= queries.length <= 100
- 1 <= queries[i].length <= 100
- 1 <= pattern.length <= 100
- All strings consists only of lower and upper case English letters.
分析
題目的意思是:給定一個字串陣列queries,和模板pattern,文queries裡面的query能夠匹配上pattern。這道題我看了一下提示,要用動態規劃啥的,頓時傻了眼。後面才發現用雙指標法也能搞定,看來我還需要沉澱。思想很簡單,遍歷queries,然後對每個字元用雙指標和pattern進行匹配。
程式碼
class Solution:
def match(self,p,q):
n=len(q)
j=0
for i in range(n):
if(j<len(p) and p[j]==q[i]):
j+=1
elif(q[i].isupper()):
return False
return j==len(p)
def camelMatch(self, queries: List[str], pattern: str) -> List[bool]:
res=[]
for query in queries:
t=self.match(pattern,query)
res.append(t)
return res
參考文獻
[LeetCode] Python - Two Pointer - Memory usage less than 100%
相關文章
- Leetcode 10 Regular Expression MatchingLeetCodeExpress
- LeetCode - 解題筆記 - 10- Regular Expression MatchingLeetCode筆記Express
- 記一次使用idea外掛CamelCase技巧Idea
- F - Perfect Matching on a Tree
- 7.2 FM Index MatchingIndex
- CF566A Matching Names
- [LeetCode Python3]10. Regular Expression Matching手把手詳解——正規表示式(一)LeetCodePythonExpress
- CF1948G MST with Matching 題解
- [ABC126F] XOR Matching 題解
- SSL - SSLHandshakeException: No subject alternative names matching IP address foundException
- Codeforces 954I Yet Another String Matching Problem
- [20240325]FORCE_MATCHING_SIGNATURE與DML.txt
- Learning Semantic Concepts and Order for Image and Sentence Matching筆記筆記
- Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of typeSpringFrameworkBeanException
- INSTALL_FAILED_NO_MATCHING_ABIS終極解決方案AI
- XAMRAIN的INSTALL_FAILED_NO_MATCHING_ABIS錯誤處理AI
- meiqua / shape_based_matching---模板匹配速度過慢問題
- Could not find a version that satisfies the requirement py4j (from versions: ) No matching distributUIREM
- Spring 異常關鍵字 no matching editors or conversion strategy found 解決方法Spring
- [20221207]為什麼FORCE_MATCHING_SIGNATURE不一致.txt
- 閱讀翻譯Hugging Face Community Computer Vision Course之Feature Matching (特徵匹配)Hugging FaceUnity特徵
- 【LeetCode】如何學習LeetCode?LeetCode
- leetcodeLeetCode
- start-stop-daemon: matching on world-writable pidfile /var/run/redis/redis-server.pid is insecurefailedRedisServerAI
- 論文閱讀-CORA: Adapting CLIP for Open-Vocabulary Detection with Region Prompting and Anchor Pre-MatchingAPT
- 一起做RGB-D-SLAM(6)g2o報錯error: no matching functionSLAMErrorFunction
- LeetCode in actionLeetCode
- leetcode 238LeetCode
- LeetCode 164 最大間距 HERODING的LeetCode之路LeetCode
- LeetCode 143 重排連結串列 HERODING的LeetCode之路LeetCode
- LeetCode問題LeetCode
- 【LeetCode】Jewels and StonesLeetCode
- Leetcode 513 javascriptLeetCodeJavaScript
- LeetCode 162 JavascriptLeetCodeJavaScript
- Leetcode 921 JavascriptLeetCodeJavaScript
- [Leetcode] Edit DistanceLeetCode
- LeetCode 克隆圖LeetCode
- LeetCode #378 JavaScriptLeetCodeJavaScript