stack_removal_order_checker
This commit is contained in:
parent
7f907700bf
commit
cfd9d8db14
@ -1,3 +1,5 @@
|
|||||||
# snippets
|
# snippets
|
||||||
|
|
||||||
Favorite code snippets
|
Favorite code snippets
|
||||||
|
|
||||||
|
All code follows the MIT license
|
9
stack_removal_order_checker.py
Normal file
9
stack_removal_order_checker.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
def check(in_list: list, out_list: list) -> bool:
|
||||||
|
stack = []
|
||||||
|
i = 0
|
||||||
|
for num in in_list:
|
||||||
|
stack.append(num)
|
||||||
|
while stack and stack[-1] == out_list[i]:
|
||||||
|
stack.pop()
|
||||||
|
i += 1
|
||||||
|
return not stack
|
Loading…
Reference in New Issue
Block a user