본문 바로가기

전체 글502

LeetCode 74(Search a 2D Matrix, java) 0. 문제 https://leetcode.com/problems/search-a-2d-matrix/ Search a 2D Matrix - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 이중 배열(matrix)과 찾고자 하는 숫자(target)가 주어진다. - 이중 배열의 규칙과 구조를 파악하여 target을 찾는 가장 효율정인 탐색 알고리즘을 작성하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 우선 문제에서 주어지.. 2022. 4. 14.
LeetCode 36(Valid Sudoku, java) 0. 문제 https://leetcode.com/problems/valid-sudoku/ Valid Sudoku - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 이중 배열(board)이 주어진다. - 이중 배열(board)은 수도쿠 문제를 만들기 위해서 생성된 것이다. - 이 문제의 핵심은 주어진 이중 배열(board)이 수도쿠로써 이상이 없는지 파악하는 것이다. 2. 문제 해설 a) 전제 조건 - 우선 문제에서 주어진 조건을 보자.. 2022. 4. 13.
17. 고아 객체(Orphan) 0. 개요 - 이번 포스팅에서는 고아 객체란 무엇인지 알아보자. 1. 고아 객체(Orphan) a) 개념 - 고아 객체는 부모 객체와 연관 관계가 끊어진 자식 객체를 의미한다. b) orphanRemoval 옵션 - JPA는 자식 객체가 고아 객체의 상태가 되면 해당 객체를 자동으로 삭제하는 기능을 가진다. - 이는 다음 사진처럼 옵션으로 설정이 가능하다. - 위의 코드는 childList에서 삭제된 객체를 연관 관계가 끊긴 것으로 판단하여 객체 자체를 삭제한다. - 옵션을 설정한 후, 다음과 같은 코드를 실행해보자. - 위의 코드를 실행하면 다음과 같아 DELETE 쿼리가 자동으로 발생하는 것을 확인할 수 있다. - 다음 사진과 같이, 연관 관계가 끊긴 자식 객체가 DB에서 삭제된 것을 확인할 수 있다.. 2022. 4. 13.
LeetCode 118(Pascal's Triangle, java) 0. 문제 https://leetcode.com/problems/pascals-triangle/ Pascal's Triangle - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 이 문제는 배열의 길이(numRows)가 주어진다. - 문제에서 이해를 돕기위해 그림이 주어진다. - 그림과 같은 방식으로, 주어진 배열의 길이만큼 파스탈의 삼각형을 생성하는 것이 핵심이다. 2. 문제 해설 a) 첫 번째 판단 - 우선 결과를 저장할 이중 List를 .. 2022. 4. 13.
LeetCode 566(Reshape the Matrix, java) 0. 문제 https://leetcode.com/problems/reshape-the-matrix/ Reshape the Matrix - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 이중 배열(mat), 행의 수(r), 열의 수(c)가 주어진다. - 주어진 이중 배열(mat)을 주어진 행(r)과 열(c)의 형태로 변환하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 판단 - 가장 첫 번째로 파악해야 할 것은 주어진 이중 배.. 2022. 4. 13.
16. 영속성 전이(Cascade) 0. 개요 - 웹 개발 공부를 했다면 Cascade라는 단어가 익숙할 수 있다. - CSS(Cascade Style Sheet)에서 사용되는 단어이기 때문이다. - Cascade라는 단어는 폭포처럼 흐른다는 의미를 갖는다. - 이를 의역해보면 연쇄적인, 종속적인, 상속적인, 전이되는 등으로 해석할 수 있다. - 이처럼 어떤 속성을 전수하는 것을 Cascade라고 표현한다. - 이번 포스팅에서는 JPA에서 사용하는 Cascade에 대해서 알아보자. 1. 영속성 전이(Cascade) a) 영속성 전이란? - 어떤 Entity를 영속성 Context에 등록할 때, 연관 객체도 함께 등록하는 기능이다. - 즉, 어떤 Entity를 영속 상태로 만들 때, 연관 객체 또한 함께 영속 상태가 되도록 하는 것이다. -.. 2022. 4. 12.
LeetCode 121(Best Time to Buy and Sell Stock, java) 0. 문제 https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ Best Time to Buy and Sell Stock - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 1개의 배열(prices)이 주어진다. - 각 배열의 원소는 매일의 주식 가격을 의미한다. ex) prices[0] = 첫째 날의 주식 가격, prices[1] = 둘째 날의 주식 가격 - 주식을 구매하고 .. 2022. 4. 12.
LeetCode 350(Intersection of Two Arrays 2, java) 0. 문제 https://leetcode.com/problems/intersection-of-two-arrays-ii/ Intersection of Two Arrays II - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 2개의 배열(num1, num2)이 주어진다. - 두 배열의 원소를 비교하여 양쪽 배열에서 중첩되는 원소를 찾아, 배열의 형태로 반환하는 것이 문제의 핵심이다. - 다만, 한번 중복된 원소로 걸러진 원소는 다시 사.. 2022. 4. 12.
LeetCode 88(Merge Sorted Array, java) 0. 문제 https://leetcode.com/problems/merge-sorted-array/ Merge Sorted Array - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 문제에서 2개의 배열(nums1, nums2)이 주어진다. - 이 2개의 배열은 오름차순으로 정렬되어 있다. - num1 배열에 num2 배열을 병합하는데, 병합 후 모든 원소가 오름차순으로 정렬되어 있어야 한다. - 문제에서 2개의 변수(m, n)가 주어진다... 2022. 4. 12.
15. 지연 로딩 & 즉시 로딩(N + 1 문제) 0. 개요 - 이전 포스팅에서 Proxy에 대해 알아보았다. - 이번 포스팅에서는 Proxy를 이용한 지연 로딩과 즉시 로딩에 대해서 알아보자. 1. 지연 로딩 a) 예시 코드 - 다음과 같은 객체를 가지는 프로젝트가 있다고 해보자. @Entity public class Player { @Id @GeneratedValue @Column(name = "PLAYER_ID") private Long id; @Column(name = "PLAYER_NAME") private String name; @ManyToOne @JoinColumn(name = "TEAM_ID") private Team team; // Getter & Setter 생략 } @Entity public class Team { @Id @Gene.. 2022. 4. 11.
LeetCode 1(Two Sum, java) 0. 문제 https://leetcode.com/problems/two-sum/ Two Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 및 해결 전략 - 문제에서 배열(nums)과 찾는 값(target)이 주어진다. - 이 문제의 핵심은 주어진 배열의 요소 2개를 더하여 target을 만들 수 있느냐는 것이다. - 주어진 배열의 요소 2개를 더하여 target을 만들 수 있다면 두 요소의 index를 배열에 담아 결과로 반환한다. - 모.. 2022. 4. 11.
LeetCode 53(Maximum Subarray, java) 0. 문제 https://leetcode.com/problems/maximum-subarray/ Maximum Subarray - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 1. 문제 설명 - 위의 문제의 핵심은 연속적인 배열 요소의 합 중에서 가장 큰 값을 찾는 것이다. - 이 문제에서 생각해야 할 것은 어떻게 연속적인 배열의 시작 요소를 어떻게 찾을 것이냐는 것이다. - 다음 예시를 보자. nums = [-2,1,-3,4,-1,2,1,-5,4] - 위의 .. 2022. 4. 11.