当前位置:首页|资讯

GFG 52 Geek and String

作者:您是打尖儿还是住店呢发布时间:2024-09-27

Our geek loves to play with strings, Currently, he is trying to reduce the size of a string by

recursively removing all the consecutive duplicate pairs. In other words, He can apply the below

operations any number of times.


Remove all the consecutive duplicate pairs and concatenate the remaining string to replace

the original string.


Your task is to  nd the string with minimum length after applying the above operations.


Example 1:


Input:

aaabbaaccd


Output: 

ad


Explanation: 

Remove (aa)abbaaccd =>abbaaccd

Remove a(bb)aaccd => aaaccd

Remove (aa)accd => accd

Remove a(cc)d => ad

---

就是连续的字符要相互抵消,看最后还剩什么字符,如果是空的,返回Empty String,

相邻字符抵消,可以用stack来处理。



Copyright © 2024 aigcdaily.cn  北京智识时代科技有限公司  版权所有  京ICP备2023006237号-1