Binary Tree
問題 2分木が与えられる。ノードは数値を持っていて以下の条件で数値の和が最大の値を見つける問題。 条件 直接つながれている隣同士のノードは取る事ができない。 House Robber III - LeetCode 解き方 それぞれのノードについて、そのノードの値を和に含め…
問題 2分木に対するSerializeとDeserializeを実装するクラスを作る問題 leetcode.com ソースコード My simple and clear Java solution | LeetCode Discuss
問題 2分木が与えられ、与えられた深さに1行分ノードを追加するという問題 leetcode.com ソースコード
問題 2分木が与えられ、深さ順に探索する問題。 www.hackerrank.com ソースコード
問題 leetcode.com 解法 Pre-Oderで頑張る。 Tree traversal - Wikipedia
問題 leetcode.com それぞれのノードのleft, rightプロパティを交換すればOK。 ソースコード
Problem leetcode.com Solution This problem can be solve by DFS with depth of tree. In my code, lists.size() == depth means that the traversing depth changes. Source Code
What is Heap Reference www.youtube.com Heap is the tree structure that has two following restrictions. Binary Tree Parent node is smaller or bigger than children nodes. Heap is good at controlling the relation about small and large. So hea…
Problem You are given a binary tree in which each node contains a value. Design an algorithm to print all paths which sum to a given value. The path dose not need to start or end at the root or leaf. Solution First, let’s approach this pro…
Problem You have two large binary tree: T1, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of T1. A tree T2 is a subtree of T1 if there exists a node n in T1 such the the subtree of…
Problem Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid storing additional nodes in a data structure. Node: This is not necessarily a binary search tree. Solution I’ll solve this pr…
Problem Given a binary tree, design a algorithm which creates a linked list of all the nodes at each depth (e.g, if you have a tree with depth D, you'll have D linked lists) How to Solve The important point of the this problem How we shoul…
Problem Implement a function to check if a binary tree is balanced. For the purposes of this question. balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one. How to Solve …
Problem https://leetcode.com/problems/binary-tree-longest-consecutive-sequence/ How to Solve This problem is classified into Tree and can be solve by using DFS(Depth First Search). Depth First Search Firstly, I thought the only search by D…