본문 바로가기

전체 글502

LeetCode 232(Implement Queue using Stacks, java) 0. 문제 https://leetcode.com/problems/implement-queue-using-stacks/ Implement Queue using Stacks - 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. 문제 설명 - 이 문제는 Stack 자료구조 2개를 이용하여 Queue를 구현하는 것이 핵심이다. - Stack 자료구조 2개를 이용하여 Queue의 메서드를 모두 구현해야 한다. 2. 문제 해설 a) 첫 번째 접근 - 가장 근본적인 원리를.. 2022. 4. 18.
LeetCode 20(Valid Parentheses, java) 0. 문제 https://leetcode.com/problems/valid-parentheses/ Valid Parentheses - 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. 문제 설명 - 문제에서 문자열(s)이 주어진다. - 문자열(s)은 괄호(), 중괄호{}, 대괄호[]로 이루어진다. - 문자열 내부의 괄호가 순서대로 짝에 맞게 열리고 닫히는지를 파악하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 괄호의 순서와 짝을 파악하는 것.. 2022. 4. 18.
LeetCode 83(Remove Duplicates from Sorted List, java) 0. 문제 https://leetcode.com/problems/remove-duplicates-from-sorted-list/ Remove Duplicates from Sorted List - 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. 문제 설명 - 문제에서 오름차순으로 정렬된 연결 리스트(head)가 주어진다. - 해당 연결 리스트 내부에는 중복된 value를 가진 노드가 존재한다. - 각 value가 한 번씩만 사용되도록 중복된 value를 가진 .. 2022. 4. 17.
LeetCode 206(Reverse Linked List, java) 0. 문제 https://leetcode.com/problems/reverse-linked-list/ Reverse Linked List - 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. 문제 설명 - 문제에서 연결 리스트(head)가 주어진다. - 해당 연결 리스트를 역순으로 재 정렬해서 반환하는 것이 문제의 핵심이다. 2. 문제 해설 - 이 문제는 연결 리스트라는 자료구조의 특성과 재귀 함수를 이해하고 있어야 풀 수 있는 문제다. a) 첫 번째 접근 -.. 2022. 4. 17.
LeetCode 203(Removed Linked List Elements, java) 0. 문제 https://leetcode.com/problems/remove-linked-list-elements/ Remove Linked List Elements - 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. 문제 설명 - 문제에서 연결 리스트(head)와 찾고자 하는 값(val)이 주어진다. - 이 문제의 핵심은 연결 리스트 내부의 모든 노드 중 찾고자 하는 값과 동일한 value를 가진 노드를 삭제하는 것이다. 2. 문제 해설 a) 첫 번째 접근.. 2022. 4. 17.
19. 값 타입(2) - 문제점과 불변 객체 0. 개요 * 본 포스팅은 이전 포스팅과 이어지는 내용임을 알립니다. - 이전 포스팅에서 값 타입에 대해서 알아보았다. - 이번 포스팅에서는 값 타입을 사용할 때 발생하는 문제점과 이를 해결하기 위해 사용하는 불변 객체에 대해서 알아보자. 1. 값 타입을 사용하는 이유 - 이전 포스팅에서 값 타입에 대해서 배웠다. - 굳이 값 타입을 사용하는 이유가 무엇일까 생각해볼 필요가 있다. - 왜냐면 JPA를 사용하므로, 이미 객체지향적 프로그래밍을 달성했다고 볼 수 있기 때문이다. a) 굳이 값 타입을 사용하는 이유 - 값 타입을 사용하는 이유는 객체의 내용을 조금이라도 더욱 간소화하기 위함이다. - 그러므로 값 타입 또한 단순하고 간단한 구조를 이뤄야 한다. - 더불어, 값 타입을 사용함에 있어서 그 안정성이.. 2022. 4. 15.
LeetCode 21(Merge Two Sorted Lists, java) 0. 문제 https://leetcode.com/problems/merge-two-sorted-lists/ Merge Two Sorted Lists - 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개의 연결 리스트(list1, list2)가 주어진다. - 두 연결 리스트는 오름차순으로 정렬되어있다. - 두 연결 리스트를 오름차순으로 병합하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 우선 문제에서 주어진 연결 .. 2022. 4. 15.
LeetCode 141(Linked List Cycle, java) 0. 문제 https://leetcode.com/problems/linked-list-cycle/ Linked List Cycle - 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. 문제 설명 - 문제에서 한 개의 연결 리스트(head)가 주어진다. - 연결 리스트를 탐색하여 순환이 존재하는지 판단하는 것이 문제의 핵심이다. 2. 문제 해설 - 이 문제는 자칫 어려워 보일 수 있다. - 다만, 문제의 제약조건을 힌트로 사용한다면 굉장히 쉽게 풀리는 문제이다... 2022. 4. 15.
LeetCode 242(Valid Anagram, java) 0. 문제 https://leetcode.com/problems/valid-anagram/ Valid Anagram - 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개의 문자열(s, t)이 주어진다. - 문자열 t가 문자열 s의 아나그램인지 판별하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 우선 각 문자열의 길이를 구한다. - 만약 길이가 동일하지 않다면 아나그램이 될 수 없다. b) 두 번째 접근 - 각 문.. 2022. 4. 15.
18. 값 타입(1) - 개념 0. 개요 - 이번 포스팅에서는 JPA의 데이터 타입에 대해서 알아보자. 1. 값 타입 - JPA는 두 가지 데이터 타입을 사용한다. a) Entity 타입 - JPA의 최상위 타입이다. - @Entity로 정의된 클래스 객체를 의미한다. - Entity 타입은 값이 변경되어도 식별자(= id, PK)를 이용하여 추적이 가능하다. ex) 게시판의 1번 글(= 객체)의 내용이 수정 또는 삭제되어도 1번 아이디를 이용하여 객체의 상태를 추적할 수 있다. b) 값 타입 - int, String, Integer와 같이 자바의 Primitive 또는 Wrapper 클래스를 이용하여 생성된 객체 - 식별자가 없으므로 값의 변경 시 추적이 불가능하다. ex) int a = 100이라면, 이를 a = 200으로 변경해.. 2022. 4. 14.
LeetCode 383(Ransom Note, java) 0. 문제 https://leetcode.com/problems/ransom-note/ Ransom Note - 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개의 문자열(ransomNote, magazine)이 주어진다. - magazine을 구성하는 문자를 이용하여 ransomNote와 동일한 문자열을 만들 수 있는냐가 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 이 문제는 Magazine과 ransomNote을 구.. 2022. 4. 14.
LeetCode 387(First Unique Character in a String, java) 0. 문제 https://leetcode.com/problems/first-unique-character-in-a-string/ First Unique Character in a String - 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. 문제 설명 - 문제에서 문자열(s)이 주어진다. - 문자열을 구성하는 문자 중 가장 첫 번째로 중복이 없는 문자를 찾아 해당 문자의 index를 반환하는 것이 문제의 핵심이다. 2. 문제 해설 - 이 문제를 풀기 위해서.. 2022. 4. 14.