![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
tree
Vendredimatin
这个作者很懒,什么都没留下…
展开
-
Leetcode tree Top Interview Questions 12道题总结
本篇文章是对leetcode tree和Top Interview Questions标签下12道array类型题目的总结Leetcode 104. Maximum Depth of Binary Tree此题需要求一颗二叉树的最大深度,可归结于树的遍历问题解:使用DFS,添加一个depth参数,每递归一层,depth++,并且每次求最大值Leetcode 230. Kth Smalles...原创 2020-02-03 21:30:52 · 117 阅读 · 0 评论 -
Leetcode 98. Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node’s key.The rig...原创 2020-02-03 20:51:03 · 103 阅读 · 0 评论 -
116/117. Populating Next Right Pointers in Each Node I/II
先看116Given a binary treestruct 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 sho...原创 2020-02-02 20:27:10 · 176 阅读 · 0 评论 -
Leetcode 124. Binary Tree Maximum Path Sum
Given a non-empty binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connection...原创 2020-02-02 20:03:34 · 90 阅读 · 0 评论 -
Leetcode 101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric:method 1这道题一开始思路就往复杂的方向思考,导致写的几个版本都有问题。看了答案...原创 2020-02-02 19:49:25 · 88 阅读 · 0 评论 -
Leetcode 108. Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the ...原创 2020-02-02 19:44:44 · 84 阅读 · 0 评论 -
Leetcode 230. Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST’s total elements.method 1树的问题一般即树的遍历问题,考虑前序、中序、后...原创 2020-02-02 19:39:10 · 78 阅读 · 0 评论 -
Leetcode 94. Binary Tree Inorder Traversal +
本篇主要记录两个算法代码中序非递归算法class Solution {public: vector<int> inorderTraversal(TreeNode* root) { vector<int> ans; stack<TreeNode*> s; s.push(root); while (!s....原创 2020-02-02 19:31:10 · 77 阅读 · 0 评论 -
Leetcode 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.Note: A leaf is a node with no children....原创 2020-01-31 18:30:32 · 64 阅读 · 0 评论