From cfd9d8db14bf01376fb5f8618b99e59c884a30fb Mon Sep 17 00:00:00 2001 From: Bigsk Date: Mon, 6 Jun 2022 23:54:10 +0800 Subject: [PATCH] stack_removal_order_checker --- README.md | 4 +++- stack_removal_order_checker.py | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 stack_removal_order_checker.py diff --git a/README.md b/README.md index 7edfb54..01bb04c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # snippets -Favorite code snippets \ No newline at end of file +Favorite code snippets + +All code follows the MIT license \ No newline at end of file diff --git a/stack_removal_order_checker.py b/stack_removal_order_checker.py new file mode 100644 index 0000000..4d24b20 --- /dev/null +++ b/stack_removal_order_checker.py @@ -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 \ No newline at end of file