분류 전체보기502 LeetCode 94(Binary Tree In-order Traversal, java) 0. 문제 https://leetcode.com/problems/binary-tree-inorder-traversal/ Binary Tree Inorder Traversal - 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. 문제 설명 - 문제에서 이진트리(root)가 주어진다. - 주어진 이진트리를 중위 순회 순서로 탐색하여, 방문한 노드의 값을 배열에 담아 반환하는 것이 문제의 핵심이다. 2. 문제 해설 a) 첫 번째 접근 - 우선 중위 순회는 좌측 자식.. 2022. 4. 19. 20. 값 타입(3) - 객체 비교와 equals() 재정의 0. 개요 - 이번 포스팅에서는 값 타입 객체를 이용한 비교에 대해서 알아보자. 1. 값 비교 a) 일반적인 값 비교 - 일반적으로 Java에서는 값을 비교할 때 비교 연산자(==)와 equals를 사용한다. → 동일성(identity) 비교: 비교 연산자(==)를 사용하여 참조 값을 비교한다. 즉, 메모리 주소 값을 비교한다. → 동등성(equivalance) 비교: equals() 메서드를 사용하여 객체의 내용을 비교한다. 즉, 객체의 값(= value)을 비교한다. - 다음 예시를 살펴보자. public class JpaMain { public static void main(String[] args) { Integer a = new Integer(10); Integer b = new Integer(.. 2022. 4. 18. LeetCode 144(Binary Tree Preorder Traversal, java) 0. 문제 https://leetcode.com/problems/binary-tree-preorder-traversal/ Binary Tree Preorder Traversal - 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. 문제 설명 - 문제에서 이진트리(root)가 주어진다. - 이 문제는 이진트리를 전위 순회(Preorder)로 탐색하여 방문한 노드를 리스트로 반환하는 것이 핵심이다. - 이진 트리를 탐색하는 방법에는 3가지가 있다. → 전위 순회(.. 2022. 4. 18. 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. 이전 1 ··· 7 8 9 10 11 12 13 ··· 56 다음