#二分木
ほぼ日刊競プロ leetcode 543. Diameter of Binary Tree
543. 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
ほぼ日刊競プロ leetcode 108. Convert Sorted Array to Binary Search Tree
108. Convert Sorted Array to Binary Search Tree
Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.
A height-balanced bina
ほぼ日刊競プロ leetcode 226. Invert Binary Tree
226. Invert Binary Tree
Given the root of a binary tree, invert the tree, and return its root.
考えたこと左と右のノードを入れ替えるだけで良い.
# Definition for a binary tree node.# class TreeNode:# def __init__(self,
ほぼ日刊競プロ leetcode 617. Merge Two Binary Trees
617. Merge Two Binary Trees
You are given two binary trees root1 and root2.Imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not
ほぼ日刊競プロ leetcode 145. Binary Tree Postorder Traversal
145. Binary Tree Postorder Traversal
Given the root of a binary tree, return the postorder traversal of its nodes' values.
二分木が与えられるので,値を帰りがけ法で探索し値を返せ
考えた事帰りがけ方のなので以下のように探索する必要がある.
根のノードが最後に来るように探索
ほぼ日刊競プロ leetcode 104. Maximum Depth of Binary Tree
104. 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
ほぼ日刊競プロ leetcode 938. Range Sum of BST
938. Range Sum of BST
Given the root node of a binary search tree and two integers low and high, return the sum of values of all nodes with a value in the inclusive range [low, high].
考えたこと上記のように2分木に
ほぼ日刊競プロ leetcode 101. Symmetric Tree
101. Symmetric Tree
Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).
考えたことまず初めにinorderでリストに追加していき,逆にした時と一致すれば正解なのでは?と考えた
# Definition for
ほぼ日刊競プロ leetcode 94. Binary Tree Inorder Traversal
94. Binary Tree Inorder Traversal
Given the root of a binary tree, return the inorder traversal of its nodes' values.
考えたこと二分木のinorderについて,よく知らなかったのでググる.
wikipediaより #間順・中間順・通りがけ順 (英: in-order) #もしあ