Algorithm/LeetCode
-
[stack] valid parenthesesAlgorithm/LeetCode 2025. 6. 7. 11:42
✅ Problemhttps://leetcode.com/problems/valid-parentheses/description/ ✅ Approach & Solution방식1) stack, map 사용더보기class Solution { public boolean isValid(String s) { // 유효성 검증을 위한 스택 선언 Deque stack = new ArrayDeque(); // 매핑 테이블 선언 Map table = new HashMap(){{ put(')', '('); put('}', '{'); put(']', '['); }}; // 한 문자씩 처리 ..
-
[linked list] reverse linked list 2Algorithm/LeetCode 2025. 6. 6. 12:11
✅ Problemhttps://leetcode.com/problems/reverse-linked-list-ii/description/ ✅ Approach & Solution방식)더보기head 노드를 가리키는 임시 노드를 생성한다.start와 end 노드를 고정하고 한 단계씩 뒤집기를 수행한다./** * 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.next ..
-
[linked list] odd even linked listAlgorithm/LeetCode 2025. 5. 25. 10:03
✅ Problemhttps://leetcode.com/problems/odd-even-linked-list/description/ ✅ Approach & Solution방식)더보기주어진 노드를 사용해 odd 노드는 odd 노드끼리, even 노드는 even 노드끼리 연결한다.odd 노드의 마지막과 even 노드의 첫 번째 연결한다./** * 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..
-
[linked list] swap nodes in pairsAlgorithm/LeetCode 2025. 5. 4. 11:45
✅ Problemhttps://leetcode.com/problems/swap-nodes-in-pairs/description/ ✅ Approach & Solution방식)더보기아래 작업을 하나의 사이클로 수행ex) dummy -> 노드1 -> 노드2 -> 노드3 -> 노드4 패턴화 시키기 위해 dummy 노드 추가노드1과 노드2 swapdummy가 노드2를 가리키도록 업데이트/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode() {} * ListNode(int val) { this.val = val; } * ListNode(int ..