2022-03-27 18:35:17 +08:00
< p > You are given a string < code > s< / code > and an integer < code > k< / code > , a < code > k< / code > < strong > duplicate removal< / strong > consists of choosing < code > k< / code > adjacent and equal letters from < code > s< / code > and removing them, causing the left and the right side of the deleted substring to concatenate together.< / p >
< p > We repeatedly make < code > k< / code > < strong > duplicate removals< / strong > on < code > s< / code > until we no longer can.< / p >
2023-12-09 18:42:21 +08:00
< p > Return < em > the final string after all such duplicate removals have been made< / em > . It is guaranteed that the answer is < strong > unique< / strong > .< / p >
2022-03-27 18:35:17 +08:00
< p > < / p >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 1:< / strong > < / p >
2022-03-27 18:35:17 +08:00
< pre >
< strong > Input:< / strong > s = " abcd" , k = 2
< strong > Output:< / strong > " abcd"
< strong > Explanation: < / strong > There' s nothing to delete.< / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 2:< / strong > < / p >
2022-03-27 18:35:17 +08:00
< pre >
< strong > Input:< / strong > s = " deeedbbcccbdaa" , k = 3
< strong > Output:< / strong > " aa"
< strong > Explanation:
< / strong > First delete " eee" and " ccc" , get " ddbbbdaa"
Then delete " bbb" , get " dddaa"
Finally delete " ddd" , get " aa" < / pre >
2023-12-09 18:42:21 +08:00
< p > < strong class = "example" > Example 3:< / strong > < / p >
2022-03-27 18:35:17 +08:00
< pre >
< strong > Input:< / strong > s = " pbbcggttciiippooaais" , k = 2
< strong > Output:< / strong > " ps"
< / pre >
< p > < / p >
< p > < strong > Constraints:< / strong > < / p >
< ul >
< li > < code > 1 < = s.length < = 10< sup > 5< / sup > < / code > < / li >
< li > < code > 2 < = k < = 10< sup > 4< / sup > < / code > < / li >
2023-12-09 18:42:21 +08:00
< li > < code > s< / code > only contains lowercase English letters.< / li >
2022-03-27 18:35:17 +08:00
< / ul >