
https://leetcode.com/problems/minimum-distance-between-bst-nodes/ Minimum Distance Between BST Nodes - 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 Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nod..
The Tribonacci sequence Tn is defined as follows: T0 = 0, T1 = 1, T2 = 1, and Tn+3 = Tn + Tn+1 + Tn+2 for n >= 0. Given n, return the value of Tn. Example 1: Input: n = 4 Output: 4 Explanation: T_3 = 0 + 1 + 1 = 2 T_4 = 1 + 1 + 2 = 4 Example 2: Input: n = 25 Output: 1389537 Constraints: 0
https://leetcode.com/problems/range-sum-of-bst/ Range Sum of BST - 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 Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive). The binary search tree is guaranteed to have..

이진 트리는 각각의 노드가 있고 각 노드는 최대 2개의 자식 노드를 가질수 있다. 맨위 의 노드는 루트(root)라고 불리고각 노드들은 유티크한 값을 가진다. 가장 흔하게 쓰이는 이진 트리는 이진 탐색 트리로 왼쪽에는 노드보다 작은 숫자 오른쪽에는 노드보다 큰 숫자가 온다. 노드를 넣는 과정 : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 private Node addRecursive(Node current, int value) { if (current == null) { return new Node(value); } if (value current.value) { current.right = addRecursive(current.right, value); } else { // ..
- 재귀 함수란 어떠한 함수에서 자기 자신을 다시 호출하여서 작업을 시키는 것을 말한다. 예 : 1 2 3 4 5 6 public int sum(int n) { if (n >= 1) { return sum(n - 1) + n; } return n; } cs 0 에서 n까지의 숫자를 리턴하는 함수이다. 재귀 함수는 2가지의 조건을 가져야한다. 1. 정지 조건 : 재귀 함수는 어떠한 조건이 만족했을시 더 이상의 재귀함수를 부르지 않고 값을 리턴해야한다. 2. 재귀 호출 : 재귀 함수는 정지 조건을 만날때까지 계속 호출되어야 한다. 재귀 함수는 두가지 종류가 있다. 꼬리재귀와 재귀(머리재귀)함수가 있는데 재귀 함수를 부르는 부분이 마지막에 있으면 꼬리재귀이고 아니면 그냥 재귀 함수이다. 1 2 3 4 5 6 ..
https://leetcode.com/problems/baseball-game/ Baseball Game - 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 You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 following types: Integer (one round's score): Directly represents the num..
https://leetcode.com/problems/backspace-string-compare/ Backspace String Compare - 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 Given two strings S and T, return if they are equal when both are typed into empty text editors. # means a backspace character. Example 1: Input: S = "..

스택은 LIFO(Last in First Out)구조 이고 큐는 FIFO(First in First out) 구조이다. 스택 구조를 이용해서 큐를 구현할수가 있다. 먼저 큐의 push 구현이다. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 /** Push element x to the back of queue. */ public void push(int x) { //스택의 모든 내용물을 save에 임시 저장해둠 while(!stack.isEmpty()) { save.push(stack.pop()); } //스택에 해당 데이터를 집어넣고 stack.push(x); //save에 임시 저장해두었던 것을 다시 stack에 집어넣음 이렇게 하면 맨 처음 인덱스로 해당 데이터가 집어넣어짐 while..

스택은 자료구조중 하나의 형태이다. LIFO(Last In First Out) 형태로 마지막에 들어갔던 데이터가 첫번째로 나가는 구조로 되어있다. 데이터가 들어가는 과정을 push 라고 하고 마지막 스택으로 쌓인다. 데이터가 나가는 과정을 pop이라고 하고 마지막 스택이 사라진다. peek은 마지막으로 들어온 데이터를 읽는 것을 뜻한다.스택은 배열, 링크드 리스트, 포인터등 광범위하게 적용할수가 있다. 마지막으로 들어온 데이터를 top 이라고 부른다. 스택이 push 되는 과정 1. 스택이 full 인지 확인한다 2. full 일경우 에러를 던지고 과정을 중단한다. 3. full 이 아닐경우 top을 1 증가시킨다. 4. 해당 top의 자리에 데이터를 집어넣는다. 5. 성공 메세지를 리턴 시킨다. 스택이..