Adjacent Elimination¶
Table of Contents¶
- 2696. Minimum String Length After Removing Substrings (Easy)
- 1047. Remove All Adjacent Duplicates In String (Easy)
- 1544. Make The String Great (Easy)
- 1003. Check If Word Is Valid After Substitutions (Medium)
- 2216. Minimum Deletions to Make Array Beautiful (Medium)
- 1209. Remove All Adjacent Duplicates in String II (Medium)
- 2211. Count Collisions on a Road (Medium)
- 735. Asteroid Collision (Medium)
- 1717. Maximum Score From Removing Substrings (Medium)
- 2197. Replace Non-Coprime Numbers in Array (Hard)
- 2751. Robot Collisions (Hard)
2696. Minimum String Length After Removing Substrings¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: string, stack, simulation
1047. Remove All Adjacent Duplicates In String¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: string, stack
1544. Make The String Great¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: string, stack
- Remove all adjacent characters that are the same and have different cases.
- Steps for the string
leEeetcode
:
char | action | stack |
---|---|---|
l | push | "l" |
e | push | "le" |
E | pop | "l" |
e | push | "le" |
e | push | "lee" |
t | push | "leet" |
c | push | "leetc" |
o | push | "leetco" |
d | push | "leetcod" |
e | push | "leetcode" |
1544. Make The String Great - Python Solution
# Stack
def makeGood(s: str) -> str:
stack = []
for i in range(len(s)):
if stack and stack[-1] == s[i].swapcase():
stack.pop()
else:
stack.append(s[i])
return "".join(stack)
print(makeGood("leEeetcode")) # "leetcode"
1003. Check If Word Is Valid After Substitutions¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: string, stack
2216. Minimum Deletions to Make Array Beautiful¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, stack, greedy
1209. Remove All Adjacent Duplicates in String II¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: string, stack
2211. Count Collisions on a Road¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: string, stack, simulation
735. Asteroid Collision¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: array, stack, simulation
1717. Maximum Score From Removing Substrings¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: string, stack, greedy
2197. Replace Non-Coprime Numbers in Array¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, math, stack, number theory
2751. Robot Collisions¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, stack, sorting, simulation