[Golang][Leetcode][BinaryTree]刷題系列-116-Populating Next Right Pointers in Each Node

116. Populating Next Right Pointers in Each Node Level : Medium 原題連結 :Click 題目 : You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition: struct Node { int val; Node *left; Node *right; Node *next; } Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.

[Golang][Leetcode][BinaryTree]刷題系列-515-Find Largest Value in Each Tree Row

515. Find Largest Value in Each Tree Row Level : Medium 原題連結 :Click 題目 : Given the root of a binary tree, return an array of the largest value in each row of the tree (0-indexed). Example : Note Example 1: Input: root = [1,3,2,5,3,null,9] Output: [1,3,9] Example 2: Input: root = [1,2,3] Output: [1,3] Example 3: Input: root = [1] Output: [1] Example 4: Input: root = [1,null,2] Output: [1,2]

[Golang][Leetcode][BinaryTree]刷題系列-104-Minimum Depth of Binary Tree

111. Minimum Depth of Binary Tree Level : Easy 原題連結 :Click 題目 : Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children. Example : Note Example 1: Input: root = [3,9,20,null,null,15,7] Output: 2 Example 2: Input: root = [2,null,3,null,4,null,5,null,6] Output: 5

[Golang][Leetcode][BinaryTree]刷題系列-104-Maximum Depth of Binary Tree

104. Maximum Depth of Binary Tree Level : Easy 原題連結 :Click 題目 : 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 node. Example : Note Example 1: Input: root = [3,9,20,null,null,15,7] Output: 3 Example 2: Input: root = [1,null,2] Output: 2 Example 3:

[Golang][Leetcode][BinaryTree]刷題系列-429-N-ary Tree Level Order Traversal

429. N-ary Tree Level Order Traversal Level : Medium 原題連結 :Click 題目 : Given an n-ary tree, return the level order traversal of its nodes' values. Nary-Tree input serialization is represented in their level order traversal, each group of children is separated by the null value (See examples). Example : Note Example 1: Input: root = [1,null,3,2,4,null,5,6] Output: [[1],[3,2,4],[5,6]] Example 2: Input: root = [1,null,2,3,4,5,null,null,6,7,null,8,null,9,10,null,null,11,null,12,null,13,null,null,14] Output: [[1],[2,3,4,5],[6,7,8,9,10],[11,12,13],[14]] 解題思路 : 這題是level order traversal的變化題，一樣可以用queue來解決，可以參考leetcode102題解 從leetcode102題的判斷left children & right children 改成一整個Children array就可以摟!

[Golang][Leetcode][BinaryTree]刷題系列-199-Right Side View

199. Binary Tree Right Side View Level : Medium 原題連結 :Click 題目 : Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Example : Note Example 1: Input: root = [1,2,3,null,5,null,4] Output: [1,3,4] Example 2: Input: root = [1,null,3] Output: [1,3] Example 3: Input: root = [] Output: []