当前位置:网站首页>LeetCode 1047. Delete all adjacent duplicates in the string
LeetCode 1047. Delete all adjacent duplicates in the string
2022-06-24 03:10:00 【freesan44】
Title address (1047. Delete all adjacent duplicates in the string )
https://leetcode-cn.com/problems/remove-all-adjacent-duplicates-in-string/
Title Description
Give a string of lowercase letters S, Duplicate deletion selects two adjacent and identical letters , And delete them . stay S Repeat the delete operation on , Until you can't delete . Returns the final string... After all the duplicates have been deleted . The answer is guaranteed to be unique . Example : Input :"abbaca" Output :"ca" explain : for example , stay "abbaca" in , We can delete "bb" Because two letters are adjacent and the same , This is the only duplicate that can be deleted at this time . And then we get the string "aaca", There is only "aa" You can perform a duplicate deletion operation , So the last string is "ca". Tips : 1 <= S.length <= 20000 S It's only made up of lowercase letters .
Ideas
Implemented in stack mode
Code
- Language support :Python3
Python3 Code:
class Solution:
def removeDuplicates(self, s: str) -> str:
stack = []
for i in s:
if len(stack) > 0 and stack[-1] == i:
stack.pop()
else:
stack.append(i)
return "".join(stack)Complexity analysis
Make n Is array length .
- Time complexity :$O(n)$
- Spatial complexity :$O(n)$
边栏推荐
- Disaster recovery series (V) -- database disaster recovery construction
- How much is a fortress machine? Why do you need a fortress machine?
- Disk and file system (Simplified)
- Lua language development, esp8266 access to Bafa cloud, mqtt and TCP protocols
- Storage crash MySQL database recovery case
- Is your database "cloud native"?
- Where is the cloud game server? Can individuals rent cloud game servers?
- Grpc: implement service end flow restriction
- What is the use of cloud desktop security server configuration? What should I do?
- Permission maintenance topic: domain controller permission maintenance
猜你喜欢
![[51nod] 3216 Awards](/img/94/fdb32434d1343040d711c76568b281.jpg)
[51nod] 3216 Awards

2022-2028 global tungsten copper alloy industry research and trend analysis report

2022-2028 global medical coating materials industry research and trend analysis report

2022-2028 global high tibial osteotomy plate industry research and trend analysis report
![[51nod] 2653 section XOR](/img/2d/cb4bf4e14939ce432cac6d35b6a41b.jpg)
[51nod] 2653 section XOR

2022-2028 global aircraft front wheel steering system industry research and trend analysis report

2022-2028 global pilot night vision goggle industry research and trend analysis report

Permission maintenance topic: domain controller permission maintenance
![[51nod] 2106 an odd number times](/img/af/59b441420aa4f12fd50f5062a83fae.jpg)
[51nod] 2106 an odd number times

2022-2028 global cancer biopsy instrument and kit industry research and trend analysis report
随机推荐
Vscode common shortcut keys, updating
Gartner released the magic quadrant of enterprise low code platform in 2021. Low code integrated platform becomes a trend!
Tencent cloud CVM starts IPv6
[summary of interview questions] zj6 redis
[summary of interview questions] zj5
2022-2028 global marine wet exhaust hose industry research and trend analysis report
Why does the fortress machine use an application publisher? What are the main functions of the fortress machine
How much is a fortress machine? Why do you need a fortress machine?
How to strengthen prison security measures? Technologies you can't imagine
New Google brain research: how does reinforcement learning learn to observe with sound?
How does the fortress machine connect to the server? Which is easy to use, fortress machine or firewall?
Tencent cloud launched its new 100g+ cloud server product!! Expect more than 400g+ in the future!
How do I check the trademark registration number? Where do I need to check?
Concise and practical time code
VNC enters the password and goes around for a long time before entering the desktop. Use procmon to locate the reason
Is your database "cloud native"?
What is the meaning of scdo? Is it comparable to bGH
Production line motor monitoring and maintenance - application case of 5g edge calculation for paperboard line motor maintenance
Grpc: based on cloud native environment, distinguish configuration files
Process kill problem