当前位置:网站首页>LeetCode 1047 Remove all adjacent duplicates in a string
LeetCode 1047 Remove all adjacent duplicates in a string
2022-07-29 20:04:00 【Gordennizaicunzai】
1047.Remove all adjacent duplicates in a string
Simple Difficulty 410 Favorites and Sharing Switch to English to receive dynamic feedback
Given the string S consisting of lowercase letters, the duplicate removal selects two adjacent and identical letters and deletes them.
Repeat deduplication on S until no further deletions are possible.
Returns the final string after all deduplication operations are done.The answer is guaranteed to be unique.
Example:
Enter:"abbaca"Output:"ca"Explanation:For example, in "abbaca", we can delete "bb" since the two letters are adjacent and identical, this is the only duplicate that can be deleted at this time.Then we get the string "aaca", of which only "aa" can perform the deduplication operation, so the final string is "ca".
Tip:
1 <= S.length <= 20000Sconsists of lowercase English letters only.
class Solution:def removeDuplicates(self, s: str) -> str:# Use the stack, compare the ones that are not on the stack with the top of the stack, if they are the same, they will pop, and if they are not, they will be pushed into the stack.lst = []for v in s:if lst and lst[-1] == v:lst.pop()else:lst.append(v)return "".join(lst)
边栏推荐
- 数字孪生万物可视 | 联接现实世界与数字空间
- 答对这3个面试问题,薪资直涨20K
- Typescript类功能混合(mixin)使用,将多个类中功能合并到一个对象
- Typescript mix method to class with decorator
- Test basis: Redis of Nosql database
- 31个!Golang常用工具来啦(建议收藏)
- word文档里插入图片显示不完整,只显示一半,怎么处理?
- 总数据量超万亿行,玉溪卷烟厂通过正确选择时序数据库轻松应对
- C # CLI (common language infrastructure)
- 线程池 ThreadPoolExecutor 详解
猜你喜欢
随机推荐
秋招之路-经典面试题之手写字符串函数
答对这3个面试问题,薪资直涨20K
C pitfalls and pitfalls
R语言时间序列数据提取:使用xts包的first函数提取时间序列中最前面10天的数据(first 10 day)
Test basis: Redis of Nosql database
FPGA设计超前进位与8421-BCD码全加器
yarn的安装和使用(yarn安装mysql)
Neo4j Open Source NoSQL Database
牛客网剑指offer刷题练习之重构二叉树
cv2 imread()函数[通俗易懂]
High-speed passive link impedance matching routine
软件测试面试屡屡失败,面试官总是说逻辑思维混乱,怎么办?
2022暑假 动态规划总结
函数的声明与作用域
优雅实现经典的生产者消费者模式
【中标麒麟系统Your trial is EXPIRED and no VALID licens 关闭弹窗】
嵌入式开发:嵌入式基础——软件错误分类
Canal实现Mysql数据增量同步更新至Mysql/Redis
洪九果品、百果园抢滩港股,卖水果是门好生意吗?
Experience Sharing | Tips for Writing Easy-to-Use Online Product Manuals






![[数学]必备基本知识](/img/ac/f3552ef31948e1c31ce692fa87a796.png)

