2023 Dec LC challenge
關於 stack 特性
- 先進後出
- Push(): Adds an element to the top of the stack.
- Pop(): Removes and returns the top element of the stack.
- Peek(): Returns the top element of the stack without removing it from the stack.
- isEmpty(): Check whether the stack is empty.
- push 和 pop 都發生在頂端
20. Valid Parentheses
Given a string s containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.
An input string is valid if:
Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Every close bracket has a corresponding open bracket of the same type.
想法
My Code
|
|