LeetCode-20
Valid Parentheses : Given a string s containing just the characters (, ), {, }, [ and ], determine if the input string is valid.
note : s consists of parentheses only ()[]{}
Answer
:::python
class Solution: def isValid(self, s: str) -> bool: valid = [] dict_valid = { "}":"{", "]":"[", ")":"(" } for l in s: if l not in dict_valid: valid.append(l) elif not valid or dict_valid[l] != valid.pop(): return False return len(valid)==0
Result : 31ms Memory: 13.9mb
'๐ข One step' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[leetcode 739] Daily Temperature (0) | 2023.04.03 |
---|---|
[LeetCode-316] Remove Duplicate Letters (0) | 2023.03.30 |
[leetcode 92] Reverse Linked List II (0) | 2023.03.26 |
[leetcode-24] Swap-Nodes-In-Pairs_2 (0) | 2023.03.21 |
[leetcode 24] Swap Nodes in Pairs (0) | 2023.03.20 |
LeetCode-20
Valid Parentheses : Given a string s containing just the characters (, ), {, }, [ and ], determine if the input string is valid.
note : s consists of parentheses only ()[]{}
Answer
:::python
class Solution: def isValid(self, s: str) -> bool: valid = [] dict_valid = { "}":"{", "]":"[", ")":"(" } for l in s: if l not in dict_valid: valid.append(l) elif not valid or dict_valid[l] != valid.pop(): return False return len(valid)==0
Result : 31ms Memory: 13.9mb
'๐ข One step' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[leetcode 739] Daily Temperature (0) | 2023.04.03 |
---|---|
[LeetCode-316] Remove Duplicate Letters (0) | 2023.03.30 |
[leetcode 92] Reverse Linked List II (0) | 2023.03.26 |
[leetcode-24] Swap-Nodes-In-Pairs_2 (0) | 2023.03.21 |
[leetcode 24] Swap Nodes in Pairs (0) | 2023.03.20 |