Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions valid-parentheses/Lustellz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// https://leetcode.com/problems/valid-parentheses
// Rumtime: 6ms
// Memory: 59.11MB

function isValid(s: string): boolean {
let stack: string[] = [];

for (let i = 0; i < s.length; i++) {
if (["(", "{", "["].includes(s[i])) {
stack.push(s[i]);
} else {
switch (s[i]) {
case ")":
if (stack.pop() !== "(") return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stack이 비어있는 경우에 대한 예외처리를 하지 않아도 괜찮나용?

break;
case "}":
if (stack.pop() !== "{") return false;
break;
case "]":
if (stack.pop() !== "[") return false;
break;
}
}
}
return stack.length === 0;
}