Java
-
[ Tree ] 98. Validate Binary Search Tree리트코드(Leetcode) 2023. 6. 26. 12:34
1. 문제 https://leetcode.com/problems/validate-binary-search-tree/ Validate Binary Search Tree - LeetCode Can you solve this real interview question? Validate Binary Search Tree - Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: * The left subtree of a node contains only nodes with keys le leetcode.com Given the root of a bina..
-
[ Tree ] 104. Maximum Depth of Binary Tree (JAVA)리트코드(Leetcode) 2023. 6. 26. 11:24
104번 문제 https://leetcode.com/problems/maximum-depth-of-binary-tree/ Maximum Depth of Binary Tree - LeetCode Can you solve this real interview question? Maximum Depth of Binary Tree - Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf leetcode.com 1. 문제 Given the root o..
-
[ Tree ] 226. Invert Binary Tree (Java)리트코드(Leetcode) 2023. 6. 19. 17:25
1. 문제 Given the root of a binary tree, invert the tree, and return its root. 이진 트리인 root가 주어지고 해당 트리의 순서를 뒤집어 반환하라 Example 1: Input: root = [4,2,7,1,3,6,9] Output: [4,7,2,9,6,3,1] Example 2: Input: root = [2,1,3] Output: [2,3,1] Example 3: Input: root = [] Output: [] Constraints: The number of nodes in the tree is in the range [0, 100]. 100
-
[ LinkedList ] 876. Middle of the Linked List (JAVA)리트코드(Leetcode) 2023. 6. 8. 17:23
리트코드 JAVA로 876번 문제 풀이 1. 문제 내용 Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node. => head라는 이름의 링크드 리스트가 주어지고 그 리스트의 중간 노드를 반환하라. 만약 중간 노드가 2개라면 두 번째 노드를 반환하라. => 여기서 알 수 있는 것 : length가 홀수일 때와 짝수일 때를 구분해야 한다는 것! Example 1: Input: head = [1,2,3,4,5] Output: [3,4,5] Explanation: node 3이 중간 노드이다. Example 2..
-
[ Linked-List ] 1290. Convert Binary Number in a Linked List to Integer - JAVA리트코드(Leetcode) 2023. 6. 7. 17:31
* leetcode의 1290번 문제를 풀어보도록 하겠다. 일단 linked-list란 뭔지 알아야 풀 수 있을 것 같다. * linked-list란? 배열인데 node라는 공간에 value와 해당 node와 연결된 이웃 node 자체 값을 갖고 있는 배열이다. 링크 리스트는 이런 식으로 한 node에 value와 다음 이웃노드의 주소값이 있는 형태로 되어 서로가 연결되어 있다. 1290의 문제를 읽어보자. Given head which is a reference node to a singly-linked list. The value of each node in the linked list is either 0 or 1. The linked list holds the binary representatio..
-
[ Array ] JAVA | 1. Two Sum (Medium)리트코드(Leetcode) 2023. 5. 26. 16:40
1번 Two Sum Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order. => int[]인 배열 nums와 int target이 파라미터로 주어지며, nums 요소 중 두 요소의 합이 target과 동일할 때 두 숫자의 인덱스를 int[]인 배열로 반..
-
[ ArrayList ] get(), remove(), clear(), removeAll(), retainAll() 구현 02JAVA 2022. 12. 7. 10:19
⊙ ArrayList 글 더보기 더보기 2022.12.05 - [JAVA] - [ ArrayList ] ArrayList란? 2022.12.05 - [JAVA] - [ ArrayList ] size(), isEmpty(), add(), addAll() 구현 01 2022.12.07 - [JAVA] - [ ArrayList ] indexOf(), lastIndexOf(), contains(), set(), toArray(), subList(), containsAll() 구현 03 ◆ ArrayList 메서드 직접 구현하기 02 1. 메소드 정리 반환(return) 타입 메서드명 기능 int size() 배열의 사이즈. 즉, 현재 배열에 들어간 요소의 개수 boolean isEmpty() 배열이 비어있으면 ..