
Recursion
文章平均质量分 66
所难
这个作者很懒,什么都没留下…
展开
-
LeetCode-Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku原创 2014-08-16 15:55:55 · 363 阅读 · 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.Solution:Code:原创 2014-08-03 20:21:11 · 235 阅读 · 0 评论 -
LeetCode-Path Sum
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原创 2014-08-03 17:26:12 · 303 阅读 · 0 评论 -
LeetCode-Path Sum II
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 / \原创 2014-08-03 17:14:18 · 331 阅读 · 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.Solution:Code:原创 2014-08-03 21:28:37 · 398 阅读 · 0 评论 -
LeetCode-Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.Solution:Code:原创 2014-08-03 21:37:11 · 304 阅读 · 0 评论 -
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.Solution:Code:原创 2014-08-04 14:00:04 · 322 阅读 · 0 评论 -
LeetCode-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原创 2014-08-03 20:47:56 · 448 阅读 · 0 评论 -
LeetCode-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.Solution:Code:原创 2014-08-04 14:23:32 · 406 阅读 · 0 评论 -
LeetCode-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.原创 2014-08-04 14:16:12 · 363 阅读 · 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 have the same value.Solution:原创 2014-08-04 19:03:32 · 248 阅读 · 0 评论 -
LeetCode-Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1原创 2014-08-03 16:49:23 · 225 阅读 · 0 评论 -
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.原创 2014-08-01 10:50:03 · 333 阅读 · 0 评论 -
LeetCode-Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit st原创 2014-08-18 12:01:34 · 513 阅读 · 0 评论 -
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 devis原创 2014-08-06 09:40:58 · 274 阅读 · 0 评论 -
LeetCode-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原创 2014-08-06 10:05:38 · 372 阅读 · 0 评论 -
LeetCode-Unique Binary Search Trees II
Given 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 3原创 2014-08-06 15:22:11 · 239 阅读 · 0 评论 -
LeetCode-Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solutio原创 2014-08-06 17:52:36 · 417 阅读 · 0 评论 -
LeetCode-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 \原创 2014-08-06 16:09:00 · 452 阅读 · 0 评论 -
LeetCode-Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order does原创 2014-08-06 22:23:15 · 342 阅读 · 0 评论 -
LeetCode-Sort List
Sort a linked list in O(n log n) time using constant space complexity.Solution:Merge Sort原创 2014-07-28 14:56:19 · 453 阅读 · 0 评论 -
LeetCode-Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","原创 2014-07-31 10:27:37 · 266 阅读 · 0 评论 -
LeetCode-Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the to原创 2014-07-31 12:51:15 · 266 阅读 · 0 评论 -
LeetCode-Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the f原创 2014-08-04 15:18:11 · 362 阅读 · 0 评论