当前位置:网站首页>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)

边栏推荐
- JS messagechannel transport
- Analysis report on the investment market of the development planning prospect of the recommended rare earth industry research industry in 2022 (the attachment is a link to the online disk, and the rep
- ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience
- New d reflection generates ABI of C for class
- HTTP Caching Protocol practice
- Jenkins operation Chapter 5 trigger, configuration webhook, Jenkins parameterized construction
- HTTP Caching Protocol practice
- Segment in Lucene
- [high concurrency] deeply analyze the callable interface
- Cloud native annual technology inventory is released! Ride the wind and waves at the right time
猜你喜欢

PCI Verilog IP

HTTP Caching Protocol practice

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

使用VS创建静态链接库.lib并使用

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

Hustoj SPJ example

Annual inventory review of Alibaba cloud's observable practices in 2021

51 single chip microcomputer learning notes 7 -- Ultrasonic Ranging

2022 recommended high-speed rail industry research report investment strategy industry development prospect market analysis (the attachment is a link to the online disk, and the report is continuously
![ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience](/img/fd/4c24e10fc91a7ce7e709a0874ba675.jpg)
ASP. Net core 6 framework unveiling example demonstration [03]:dapr initial experience
随机推荐
JIRA basic usage sharing
[IOT] description of renaming the official account "Jianyi commerce" to "product renweipeng"
Use VS to create a static link library Lib and use
Kubernetes backup disaster recovery service product experience tutorial
Redis notes (II) operating commands for keys in redis
Pytest (7) -yield and termination function
Robot reinforcement learning - transferring end-to-end videomotor control from simulation to realworld (curl 2017)
Analysis report on the investment market situation of the development planning prospect of the recommended chip industry research industry in 2022 (the attachment is a link to the network disk, and th
How to use regex in file find
Creation of Arduino uno development environment
There are two ways for golang to develop mobile applications
New d reflection generates ABI of C for class
证券开户安全么,有没有什么危险呢
Open a new ecological posture | use WordPress remote attachment to store to Cos
Use of sed in shell script
What is MES? What does it do?
2022 recommended tire industry research report industry development prospect market analysis white paper
Research Report on the new energy industry of recommended power equipment in 2022 industry development prospect market investment analysis (the attachment is a link to the network disk, and the report
Research on heuristic intelligent task scheduling
Love that can't be met -- what is the intimate relationship maintained by video chat