일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Generator
- LeetCode
- 시바견
- 밴픽
- Convert Sorted List to Binary Search Tree
- Python
- 109. Convert Sorted List to Binary Search Tree
- Decorator
- 715. Range Module
- 파이썬
- attribute
- Python Implementation
- Python Code
- DWG
- shiba
- Substring with Concatenation of All Words
- 315. Count of Smaller Numbers After Self
- Regular Expression
- 컴퓨터의 구조
- 프로그래머스
- 운영체제
- kaggle
- iterator
- Class
- 30. Substring with Concatenation of All Words
- data science
- Protocol
- t1
- concurrency
- 43. Multiply Strings
Archives
- Today
- Total
Scribbling
[Java 101] 20. Valid Parentheses: Stack 본문
class Solution {
public boolean isValid(String s) {
Stack<Character> stack = new Stack<>();
for (var c: s.toCharArray()) {
if (c == '{' || c == '[' || c == '(') {
stack.add(c);
} else {
if (stack.empty()) return false;
Character popped = stack.pop();
if (c == '}') {
if (popped != '{') return false;
}
else if (c == ']') {
if (popped != '[') return false;
}
else if (c == ')') {
if (popped != '(') return false;
}
}
}
return stack.empty();
}
}
'Computer Science > Java' 카테고리의 다른 글
[Java 101] 102. Binary Tree Level Order Traversal - Queue (0) | 2023.03.04 |
---|---|
[Java101] LeetCode: 23. Merge k Sorted Lists: Priority Queue (0) | 2023.03.02 |
[Java 101] 76. Minimum Window Substring: Set, HashMap (0) | 2023.02.22 |
[Java 101] 125. Valid Palindrome with StringBuilder (0) | 2023.02.21 |
[Java 101] 347. Top K Frequent Elements with HashMap as a counter, PriorityQueue, (0) | 2023.02.14 |