[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
- Regular Expression Matching leetcode javaExpressLeetCodeJava
- Leetcode-Wildcard MatchingLeetCode
- Wildcard Matching leetcode javaLeetCodeJava
- [LeetCode] Regular Expression Matching 正規表示式匹配LeetCodeExpress
- LeetCode - 解題筆記 - 10- Regular Expression MatchingLeetCode筆記Express
- 【LeetCode】Wildcard Matching 串匹配 動態規劃LeetCode動態規劃
- 記一次使用idea外掛CamelCase技巧Idea
- iOS程式碼規範之駝峰命名法camelCaseiOS
- 7.2 FM Index MatchingIndex
- F - Perfect Matching on a Tree
- ACM Binary String MatchingACM
- Scala的Pattern Matching Anonymous FunctionsFunction
- [LeetCode Python3]10. Regular Expression Matching手把手詳解——正規表示式(一)LeetCodePythonExpress
- Pattern Matching Metacharacters For asm_diskstringASM
- 【故障處理】ORA-28040: No matching authentication protocolProtocol
- CF1948G MST with Matching 題解
- [20120918]理解v$sql的exact_matching_signature與force_matching_signature.txtSQL
- INSTALL_FAILED_NO_MATCHING_ABIS錯誤解決AI
- [ABC126F] XOR Matching 題解
- INSTALL_FAILED_NO_MATCHING_ABIS終極解決方案AI
- Codeforces 954I Yet Another String Matching Problem
- Learning Semantic Concepts and Order for Image and Sentence Matching筆記筆記
- cvc-complex-type.2.4.c: The matching wildcard is strict
- Git 常見問題: unable to negotiate with *.*.*.*: no matching key exchange methodfound...GitGo
- 急!!Error Parsing EJB file: Finder found in DD with no matching method.Error
- SSL - SSLHandshakeException: No subject alternative names matching IP address foundException
- Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of typeSpringFrameworkBeanException
- XAMRAIN的INSTALL_FAILED_NO_MATCHING_ABIS錯誤處理AI
- sol6459:Order of precedence for virtual server matching (9.x - 11.2.1)Server
- 開發:異常收集之 expected single matching bean but found 2Bean
- [20240325]FORCE_MATCHING_SIGNATURE與DML.txt
- meiqua / shape_based_matching---模板匹配速度過慢問題
- Could not find a version that satisfies the requirement py4j (from versions: ) No matching distributUIREM
- oracle 12c ORA-28040: No matching authentication protocol 處理辦法OracleProtocol
- spring - cvc-complex-type.2.4.c: The matching wildcard is strict,Spring
- 利用FORCE_MATCHING_SIGNATURE捕獲非繫結變數SQL變數SQL
- 解決Error (1133): Can’t find any matching row in the user tableError