当前位置:网站首页>Design of leetcode simple problem goal parser
Design of leetcode simple problem goal parser
2022-06-29 05:53:00 【·Starry Sea】
subject
Please design a string that can interpret command Of Goal Parser .command from “G”、"()" and / or “(al)” In a certain order .Goal The parser will “G” Interpreted as a string “G”、"()" Interpreted as a string “o” ,"(al)" Interpreted as a string “al” . then , Concatenate the interpreted strings into a string in the original order .
Here is the string command , return Goal Parser Yes command The result of the explanation is .
Example 1:
Input :command = “G()(al)”
Output :“Goal”
explain :Goal The parser interprets the command as follows :
G -> G
() -> o
(al) -> al
The final result of the connection is “Goal”
Example 2:
Input :command = “G()()()()(al)”
Output :“Gooooal”
Example 3:
Input :command = “(al)G(al)()()G”
Output :“alGalooG”
Tips :
1 <= command.length <= 100
command from “G”、"()" and / or “(al)” In a certain order
source : Power button (LeetCode)
Their thinking
This kind of question is relatively simple. You only need to check whether the characters conform to a certain rule according to the rules .
class Solution:
def interpret(self, command: str) -> str:
i=0
temp=''
while i<len(command):
if command[i]=='G':
temp+='G'
i+=1
elif command[i]=='(' and command[i+1]==')':
temp+='o'
i+=2
else:
temp+='al'
i+=4
return temp

class Solution:
def interpret(self, command: str) -> str:
def change(match):
char=match.group('char')
if len(char)==1:
return 'G'
elif len(char)==2:
return 'o'
else:
return 'al'
return re.sub('(?P<char>G|\(\)|\(al\))',change,command)

边栏推荐
- Research Report on the recommended lithography industry in 2022 industry development prospect market investment analysis (the attachment is a link to the network disk, and the report is continuously u
- Redis notes (II) operating commands for keys in redis
- Leetcode notes on question brushing (XIV) -- related topics of binary tree attributes in binary tree chapter
- Tcapulusdb Jun · industry news collection (V)
- Mongodb basic knowledge summary
- Call the computer calculator and use it to convert several base numbers
- Use some examples of qte5
- ICLR is going to have a big discussion on the deep generation model. Max welling and the winner of the AAAI million dollar award are here. Bengio is one of the organizers
- [high concurrency] deeply analyze the callable interface
- Purple red solid meso tetra (o-alkoxyphenyl) porphyrin cobalt (meso-t (2-rop) PCO) / tetra (n, n-diphenyl-p-amino) phenyl porphyrin (tdpatph2)
猜你喜欢

Purple red solid meso tetra (o-alkoxyphenyl) porphyrin cobalt (meso-t (2-rop) PCO) / tetra (n, n-diphenyl-p-amino) phenyl porphyrin (tdpatph2)
![[high concurrency] deeply analyze the callable interface](/img/42/43d1f0b894f2632f2c7f1bfe970708.jpg)
[high concurrency] deeply analyze the callable interface

Parsing rshub document auto generation API

Analysis report on the investment market of the development planning prospect of the recommended NFT industry research industry in 2022 (the attachment is a link to the online disk, and the report is

Tcapulusdb Jun · industry news collection (V)

2022 recommended cloud computing industry research report investment strategy industry development prospect market analysis (the attachment is a link to the online disk, and the report is continuously

It turns out that the joys and sorrows of programmers are not interlinked

Modularization and modular specification commonjs

HTTP Caching Protocol practice

2022 recommended quantum industry research industry development planning prospect investment market analysis report (the attachment is a link to the online disk, and the report is continuously updated
随机推荐
Signal slot mechanism
Ctrip launched the "3+2" office mode. Are you sour?
STI, one controller
[high concurrency] deeply analyze the callable interface
Use some examples of qte5
Structure training camp module II operation
Meso tetra (4-N, N, n-trimethylaminophenyl) porphyrin (ttmapp) /meso tetra - [4- (BOC threonine) aminophenyl] porphyrin (TAPP thr BOC) supplied by Qiyue
Summary of redis basic knowledge points
ICLR is going to have a big discussion on the deep generation model. Max welling and the winner of the AAAI million dollar award are here. Bengio is one of the organizers
C语言用 printf 打印 《爱心》《火星撞地球》等,不断更新
Mongodb basic knowledge summary
Research Report on the recommended lithography industry in 2022 industry development prospect market investment analysis (the attachment is a link to the network disk, and the report is continuously u
2022-01 Microsoft vulnerability notification
DANGER! V** caught climbing over the wall!
ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience
Jenkins operation Chapter 5 trigger, configuration webhook, Jenkins parameterized construction
Week 12 - task 2- shoulder to shoulder cadres
The first commercial spacewalk of mankind is finalized! Musk SpaceX announced a new round of space travel plan, and the American rich became repeat customers
机器人强化学习——Transferring End-to-End Visuomotor Control from Simulation to RealWorld (CoRL 2017)
Spark saving to external data source