![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Algorithms
文章平均质量分 66
nxtgo
这个作者很懒,什么都没留下…
展开
-
【Leetcode】Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.The path may start and end at any node in the tree.For example:Given the below binary tree, 1 / \ 2 3Return 6. 使用递归可解原创 2013-09-13 17:30:00 · 2282 阅读 · 0 评论 -
【Leetcode】Given a binary tree, check whether it is a mirror of itself
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).原创 2013-10-01 22:03:10 · 1656 阅读 · 0 评论 -
【Leetcode】Minimum Depth of Binary Tree
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.求一棵树的最小深度,即从根结点到叶节点路径中,最短路径中结点的个数。思路是先原创 2013-09-14 20:34:54 · 1295 阅读 · 0 评论 -
【Leetcode】Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.把一棵二叉树原地(不另外开空间)转化成链表。原创 2013-09-14 20:00:34 · 1033 阅读 · 0 评论 -
【Leetcode】Search in Rotated Sorted Array
在旋转的无重复的排序数组中查找某个数,要求时间复杂度O(logN)Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to sear原创 2013-09-17 17:33:42 · 3944 阅读 · 0 评论 -
【Leetcode】Triangle
给定一个由数字组成的三角形,从顶至底找出路径最小和。Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle原创 2013-09-17 21:21:51 · 3084 阅读 · 1 评论 -
【Leetcode】Set Matrix Zeroes
给定一个m x n的矩阵,如果某个元素为0,则把该元素所在行和列全部置0。Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.分析:最直接想到的就是遍历该矩阵,每遇到0就把它所在的行和列全部置0,但这是错的,因为这样会引入新的0到矩阵中。下一个比较容易相原创 2013-09-17 19:58:10 · 1482 阅读 · 0 评论 -
【Leetcode】Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).原创 2013-10-01 22:36:48 · 1556 阅读 · 0 评论 -
【Leetcode】Search in Rotated Sorted Array II
从一个旋转的排序数组中寻找一个数字,数组中可能有重复数字,要求时间复杂度O(LogN)。( 1 1 1 2 4 might become 1 1 2 4 1).You are given a target value to search. If found in the array return true, otherwise return false.思路:二分查找,需要注意的原创 2013-09-17 17:43:01 · 1979 阅读 · 0 评论 -
【Leetcode】Same Tree
给定两棵二叉树,判断是否相等(即树的结构以及各结点中的值都一样)Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes原创 2013-09-17 21:51:17 · 2684 阅读 · 0 评论 -
【Leetcode】Given a binary tree, find all root-to-leaf paths whose sum equals a given number
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \原创 2013-10-01 21:43:55 · 1840 阅读 · 0 评论 -
【Leetcode】Path Sum from root to leaf in binary tree
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum原创 2013-10-01 21:28:51 · 1135 阅读 · 0 评论 -
【Leetcode】Combinations
Given two integers n and k, return all possible combinations ofk numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]原创 2013-09-14 14:28:19 · 796 阅读 · 0 评论 -
【Leetcode】Combination SUM
Given a set of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited number原创 2013-09-14 14:39:42 · 1309 阅读 · 0 评论 -
【Leetcode】Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.Each number in C may only be used once in the combinatio原创 2013-09-14 14:49:08 · 1141 阅读 · 0 评论 -
【Leetcod】Unique Binary Search Trees II
给定结点数n,结点值为1,2,...,n,求由这些结点可以构成的所有二叉查找树。原创 2013-09-15 18:09:27 · 3246 阅读 · 3 评论 -
【Leetcode】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.根据中序序列和后序序列构造二叉树,后序的最后一个结点一定是根结点,该结点可以把中序序列分成左右两部分,对应于左右子树原创 2013-09-14 16:34:01 · 3595 阅读 · 0 评论 -
【Leetcode】判断一棵二叉树是不是平衡二叉树
思路1:先判断左右子树是不是平衡的,若平衡再求出左右子树的深度,若深度之差大于1,则不平衡。贴上代码:int Depth(TreeNode *root){ if (!root) return 0; return 1 + max(Depth(root->left),Depth(root->right));}bool isBalanced(TreeNode *root){ if原创 2013-09-13 15:49:59 · 7943 阅读 · 0 评论 -
【Leetcode】Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.给定一个按升序排序好的链表,把它转换成一棵平衡的二分查找树。可以首先把这个链表的长度给求出来,中间的结点就是平衡BST的根结点,它会把链表一分为二,这样就递归地建立左右子树。原创 2013-09-14 18:55:12 · 1982 阅读 · 0 评论 -
【Leetcode】Unique Binary Search Trees
假设给定n个节点,节点值为1,2,3,...,n,求由这些结点可以构成多少棵不同的二叉查找树。原创 2013-09-15 18:04:22 · 6462 阅读 · 2 评论 -
【Leetcode】Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.Recover the tree without changing its structure.Note:A solution using O(n) space is pretty straight forward. Could you devise a原创 2013-09-14 22:09:27 · 2005 阅读 · 1 评论 -
【Leetcode】Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear onlyonce and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2013-09-21 16:33:30 · 1244 阅读 · 0 评论