목록재귀 (30)
넘치게 채우기
https://leetcode.com/problems/remove-nodes-from-linked-list/description/leetcode - Remove Nodes From Linked List문제 유형 : 연결 리스트, 재귀, 스택문제 난이도 : Medium 문제You are given the head of a linked list.Remove every node which has a node with a greater value anywhere to the right side of it.Return the head of the modified linked list. 연결리스트의 head가 주어진다.노드의 다음 노드들 중 더 큰 값이 있다면, 그 노드를 삭제하라.모든 작업이 끝나고 나서의 연결 ..
https://leetcode.com/problems/sum-of-distances-in-tree/description/leetcode - Sum of Distances in Tree문제 유형 : dfs, 재귀, 트리, 다이나믹 프로그래밍문제 난이도 : Hard 문제There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.You are given the integer n and the array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.Return an array ..
https://leetcode.com/problems/freedom-trail/description/leetcode - Freedom Trail문제 유형 : 재귀 / dfs / 다이나믹 프로그래밍문제 난이도 : Hard 문제In the video game Fallout 4, the quest "Road to Freedom" requires players to reach a metal dial called the "Freedom Trail Ring" and use the dial to spell a specific keyword to open the door.Given a string ring that represents the code engraved on the outer ring and another..
https://leetcode.com/problems/smallest-string-starting-from-leaf/description/ Leetcode - Smallest String Starting From Leaf 문제 유형 : 이진트리, 재귀, dfs 문제 난이도 : Medium 문제 You are given the root of a binary tree where each node has a value in the range [0, 25] representing the letters 'a' to 'z'. Return the lexicographically smallest string that starts at a leaf of this tree and ends at the root. As a ..
https://leetcode.com/problems/add-one-row-to-tree/description/ LeetCode - Add One Row to Tree 문제 유형 : 이진트리, dfs, 재귀 문제 난이도 : Medium 문제 Given the root of a binary tree and two integers val and depth, add a row of nodes with value val at the given depth depth. Note that the root node is at depth 1. The adding rule is: Given the integer depth, for each not null tree node cur at the depth depth - 1,..
https://leetcode.com/problems/sum-of-left-leaves/description/ Leetcode - Sum of Left Leaves 문제 유형 : 이진 트리, dfs, 재귀 문제 난이도 : Easy 문제 Given the root of a binary tree, return the sum of all left leaves. A leaf is a node with no children. A left leaf is a leaf that is the left child of another node. 이진 트리의 루트가 주어진다. 모든 왼쪽 잎 노드의 값의 합을 구하시오. 잎 노드란 자식 노드가 없는 노드를 말합니다. 풀이 말 그대로 이진트리를 순회하면서 왼쪽 리프노드의 합을 반..
https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list/description/ Leetcode - Remove Zero Sum Consecutive Nodes from Linked List 문제 유형 : 연결리스트, 재귀 문제 난이도 : Medium 문제 Given the head of a linked list, we repeatedly delete consecutive sequences of nodes that sum to 0 until there are no such sequences. After doing so, return the head of the final linked list. You may retur..
https://leetcode.com/problems/find-bottom-left-tree-value/description/ Leetcode - Find Bottom Left Tree Value 문제 유형 : 트리, dfs, 재귀 문제 난이도 : Medium 문제 Given the root of a binary tree, return the leftmost value in the last row of the tree. 이진 트리의 루트가 주어진다. 트리의 마지막 행의 가장 왼쪽 값을 반환하시오. 풀이 dfs를 하면서, 각 노드의 왼쪽, 오른쪽별로 더 깊이 있는 노드를 재귀적으로 반환하면 된다. 의 형태로 값을 반환시킨다. 같은 깊이라면, 더 왼쪽의 노드를 상위 노드에 반환한다. 코드 C++ /** * ..
![](http://i1.daumcdn.net/thumb/C150x150/?fname=https://blog.kakaocdn.net/dn/ymT90/btsFkIk56VE/ShvG4rDKRHoWzziLKpwIXK/img.png)
https://leetcode.com/problems/diameter-of-binary-tree/description/ Diameter of Binary Tree - LeetCode Can you solve this real interview question? Diameter of Binary Tree - Given the root of a binary tree, return the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path leetcode.com Leetcode - Diameter of Bin..
https://leetcode.com/problems/maximum-difference-between-node-and-ancestor/description/ Maximum Difference Between Node and Ancestor - LeetCode Can you solve this real interview question? Maximum Difference Between Node and Ancestor - Given the root of a binary tree, find the maximum value v for which there exist different nodes a and b where v = |a.val - b.val| and a is an ancestor of b. A node..