- 博客(17)
- 收藏
- 关注
原创 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. 由题意得,给出一个递增的序列,然后求出它的高度平衡的二叉搜索树。题目比较简单,就用二分法,每次取序列的一半来作为子树的根的结点值,用递归的方法就可以实现,代码如下。 Code(LeetCo
2017-11-29 09:39:58 172
原创 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.Th
2017-11-27 17:19:41 165
原创 95. Unique Binary Search Trees II
Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n. For example, Given n = 3, your program should return all 5 unique BST's shown below. 1
2017-11-27 16:44:47 223
原创 96. Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For example, Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \
2017-11-26 16:21:20 180
原创 106. Construct Binary Tree from Inorder and Postorder Traversal
Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 题意是给出二叉树的中序和后序,然后构造这个二叉树,这题和105基本是一样的思想和框架,就是区间不太一
2017-11-23 12:24:00 151
原创 105. Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree. 由题意得,这题是给出一个二叉树的前序和中序序列,然后要求构造这样的一个二叉树。用递归的方法比较容易懂和好写,所
2017-11-23 11:07:27 146
原创 116. Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; } Populate each next pointer to point to its next right node.
2017-11-22 15:37:16 172
原创 110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never diffe
2017-11-21 16:23:30 163
原创 103. Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary
2017-11-17 17:25:36 161
原创 107. Binary Tree Level Order Traversal II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root). For example: Given binary tree [3,9,20,null,null,15,
2017-11-17 16:50:00 154
原创 102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20
2017-11-17 11:30:01 152
原创 145. Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1]. 题意是要求二叉树的后序遍历,那
2017-11-15 20:45:28 164
原创 94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,3,2]. 题意是对二叉树进行中序遍历,
2017-11-15 19:07:20 180
原创 144. Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree [1,null,2,3], 1 \ 2 / 3 return [1,2,3]. 题意是要先序遍历一个二叉树
2017-11-14 19:56:00 216
原创 150. Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: ["2", "1",
2017-11-14 18:26:01 166
原创 84. Largest Rectangle in Histogram
Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram. Above is a histogram where width o
2017-11-14 18:00:21 164
原创 5. Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Input: "babad" Output: "bab" Note: "aba" is also a valid answer.
2017-11-13 11:04:36 157
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人