전체 글
-
[LeetCode] 3Sum (Java)IT/Problem Solving 2024. 3. 3. 22:10
Problem Solution Two-Pointer (st, ed) 1. First, sort the array in ascending order. - In order for the sum of three numbers to be zero, at least one of the numbers must be negative. (excluding the case where all three are zero) - To simplify calculations, sort the array in ascending order first. 2. Set the pivot point (i) and two pointers (st, ed) in the sorted array. - The pivot point (i) can ra..
-
[DB] Concurrency Control (2) Concurrency Problem and Isolation LevelDB/DB Basic 2024. 2. 27. 00:11
Concurrency Problem and Isolation Level Concurrency Problem Concurrency problems occur when multiple transactions are being executed on the same database in unrestricted problems. Concurrency Problem Description Lost Update Occurs when two transactions try to update the same data concurrently, pontentially resulting in one transaction's changes being overwritten by the other Dirty Read Happens w..
-
[DB] Concurrency Control (1) Schedule, Serializability, RecoverabilityDB/DB Basic 2024. 2. 25. 22:56
Concurrency Control When multiple transactions are processed simultaneously in a single DBMS, the utilization of processors and disks increases, leading to an increase in throughput (the number of transactions processed per unit time), and there is a benefit of reduced response time as shorter transactions do not need to wait for other transactions. However, because multiple transactions are exe..
-
[DB] TransactionDB/DB Basic 2024. 2. 24. 16:53
Transaction : A logical unit of work in a database that consists of one or more operations performed on the database ACID 1. Atomicity - Transactions are all-or-nothing - Ensures that all operations within a transaction are completed successfully, or none of them are - If any part fails, the entire transaction is rolled back 2. Consistency - Maintains the database in a valid state before and aft..
-
[LeetCode] Sudoku Solver (Java)IT/Problem Solving 2024. 2. 23. 22:59
문제 문제풀이 1. 무지성 For문 - 일단 스도쿠 판의 배열이 9*9로 정해져 있고, 하나의 solution만 있는 것이 보장되기 때문에, 무지성 반복문을 계속 돌려서 값을 넣어보는 방식을 채택했다. class Solution { public void solveSudoku(char[][] board) { solve(board); } private boolean solve(char[][] board) { for (int i = 0; i < board.length; i++) { for (int j = 0; j < board.length; j++) { if (board[i][j] == '.') { for (char c = '1'; c
-
[LeetCode] Trapping Rain Water (Java)IT/Problem Solving 2024. 2. 21. 23:57
문제 문제풀이 1. 두 번 계산해주자 - DP로 풀었다. - 두 가지 경우를 나누어 앞에서 부터 탐색했을 때와 뒤에서부터 탐색했을 때를 모두 계산해줬다. 처음에 기준 높이를 가지고 앞에서 부터 탐색할 때 기준 높이보다 높거나 같은 막대를 만나지 못하면 계산이 안된다. 따라서 뒤에서 부터도 똑같은 방식으로 탐색을 해주고, DP배열을 한 번 더 돌아서 각 위치에서 더 낮은 값을 결과값으로 더해줬다. class Solution { public int trap(int[] height) { int currHeight = height[0]; int[][] dp = new int[2][height.length]; dp[0][0] = 0; dp[1][height.length - 1] = 0; for (int i = 1..
-
[LeetCode] Median of Two Sorted Arrays (Java)IT/Problem Solving 2024. 2. 4. 20:54
문제 문제풀이 감을 못 잡겠어서 이건 힌트를 보고 풀었다! 사실 이진탐색만 알면 간단하게 풀리는 문제인데, 개념을 매번 까먹었다가 아래 유튜브 영상을 보고 완벽하게 이해할 수 있었다. 구우우웃-! class Solution { public double findMedianSortedArrays(int[] nums1, int[] nums2) { if (nums1.length > nums2.length) { return findMedianSortedArrays(nums2, nums1); } // binary search int partitionLen = (nums1.length + nums2.length + 1) / 2; boolean isEven = (nums1.length + nums2.length) % ..
-
[LeetCode] Container With Most Water (Java)IT/Problem Solving 2024. 2. 4. 14:53
문제 문제풀이 과정 그리디하게 풀기엔 범위가 커서 시간초과가 날 게 분명하여 투 포인터를 이용하기로 앞쪽을 가리키는 포인터 하나와 뒤를 가리키는 포인터를 하나씩 가지고, 자기보다 큰 높이를 가진 벽을 만났을 때만 넓이를 다시 구하고 max값을 찾도록 했다. (자기보다 작은 높이를 가진 벽은 계산하나마나 넓이도 작을 것이므로) class Solution { public int maxArea(int[] height) { int st = 0; // start index int ed = height.length - 1; // end index int leftLen = height[st]; // current left length int rightLen = height[ed]; // current right le..