当前位置:网站首页>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)$
边栏推荐
- How to select a cloud game server? Which cloud game server recommends?
- How to register a trademark? What needs to be prepared?
- 2022-2028 global high tibial osteotomy plate industry research and trend analysis report
- How to apply for trademark registration? What are the steps?
- Tencent cloud CIF engineering efficiency summit ends perfectly
- Simple and beautiful weather code
- Use Charles to capture the package of the applet through the mobile agent
- What is the price of the elastic public network IP bandwidth
- Where is the cloud game server? Can individuals rent cloud game servers?
- Windowsvpn client is coveted by vulnerabilities, 53% of companies face supply chain attacks | global network security hotspot
猜你喜欢

2022-2028 global genome editing mutation detection kit industry survey and trend analysis report

2022-2028 global anti counterfeiting label industry research and trend analysis report

2022-2028 global high tibial osteotomy plate industry research and trend analysis report
![[51nod] 3047 displacement operation](/img/cb/9380337adbc09c54a5b984cab7d3b8.jpg)
[51nod] 3047 displacement operation

2022-2028 global third-party data platform industry research and trend analysis report

2022-2028 global aircraft audio control panel system industry research and trend analysis report
![[51nod] 3216 Awards](/img/94/fdb32434d1343040d711c76568b281.jpg)
[51nod] 3216 Awards
![[summary of interview questions] zj6 redis](/img/4b/eadf66ca8d834f049f3546d348fa32.jpg)
[summary of interview questions] zj6 redis

2022-2028 global marine wet exhaust hose industry research and trend analysis report

2022-2028 global cancer biopsy instrument and kit industry research and trend analysis report
随机推荐
Why should I change my PC to a cloud desktop server? What are the characteristics of this server?
Kibana report generation failed due to custom template
South Korea's national network is disconnected. Who launched the network "attack"?
How to build a speech synthesis server
Industry experts talk about "extortion virus": how does e-government build a moat?
Cloud desktop server resource planning, what are the advantages of cloud desktop
Double 11 will arrive soon. Is your website ready?
What protocols do fortress computers have and what protocols do fortress computers generally use
Tencent Youtu won the champion of iccv2021 LVIs challenge workshop and the best innovation award of the project
Where is the cloud game server? Can individuals rent cloud game servers?
How to handle the occasional address request failure in easygbs live video playback?
What protocol does FTP belong to in Fortress machine and how to use FTP in Fortress machine
What is the role of the distributed configuration center? What are the advantages of a distributed configuration center?
Use Charles to capture the package of the applet through the mobile agent
Disk and file system (Simplified)
Micro build low code enterprise exchange day · Shenzhen station opens registration
How to strengthen prison security measures? Technologies you can't imagine
System design: File Hosting Service
Instructions for performance pressure test tool
[summary of interview questions] zj6 redis