stack
-
[stack] valid parenthesesAlgorithm/LeetCode 2025. 3. 23. 11:09
✅ Problemhttps://leetcode.com/problems/valid-parentheses/description/ ✅ Approach & Solution방식1) Deque 인터페이스 사용한 Stack 구현더보기플로우(, {, [ : stack push), }, ] : stack pop빈 스택인 경우 : not valid대응하는 open bracket이 아닌 경우 : not valid빈 스택이 아닌 경우 : not validclass Solution { public boolean isValid(String s) { Deque stack = new ArrayDeque(); boolean result = true; for (int i = 0; i 방식2)..
-
[linked list] palindrome linked listAlgorithm/LeetCode 2025. 2. 16. 18:50
✅ Problemhttps://leetcode.com/problems/palindrome-linked-list/description/ ✅ Approach & Solution공통리스트의 앞과 뒤의 값을 비교하여 값이 다른 경우 팰린드롬이 아님 방식1) 추가 자료구조 사용더보기1-1) Stack 사용/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int val, ListNode next) { this.val = val; this.nex..