| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- Python
- t1
- data science
- iterator
- 109. Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- 밴픽
- Regular Expression
- 715. Range Module
- kaggle
- Generator
- 운영체제
- concurrency
- Python Code
- LeetCode
- 파이썬
- shiba
- 프로그래머스
- DWG
- Substring with Concatenation of All Words
- 30. Substring with Concatenation of All Words
- attribute
- Decorator
- Protocol
- Class
- Python Implementation
- 시바견
- Convert Sorted List to Binary Search Tree
- 컴퓨터의 구조
- 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 |