Binary Tree Paths

2016-11-26
阅读 1 分钟
1.5k
Binary Tree PathsGiven a binary tree, return all root-to-leaf paths. For example, given the following binary tree: {代码...} All root-to-leaf paths are: {代码...} 1.解题思路 求根节点到叶子节点的路径集合,采用深度搜索,利用递归实现。 2.代码 {代码...}

Longest Increasing Subsequence

2016-11-21
阅读 1 分钟
1.4k
Longest Increasing SubsequenceGiven an unsorted array of integers, find the length of longest increasing subsequence.

Reverse Linked List I II

2016-11-21
阅读 2 分钟
2k
Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?

Kth Largest Element in an Array,Top K Frequent Elements

2016-11-21
阅读 2 分钟
2.2k
Kth Largest Element in an ArrayFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.

Merge k Sorted Lists

2016-11-21
阅读 1 分钟
2.4k
Merge k Sorted ListsMerge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.

Insertion Sort List,Merge Two Sorted Lists,Sort List

2016-11-21
阅读 3 分钟
2.2k
题目很简单,就是要求用插入排序的方法来为链表排序。插入排序就是每次遍历一个新的元素,将其插入到前面已经排好序的元素中。因为头结点没法确定,所以我们用一个dummy节点;然后开始向后逐个遍历,当前遍历的节点为cur,另外sortnode每次都指向已经排好序的第一个节点dummy,然后从dummy开始往后,直到找到sortnode.next...

[Leetcode]Longest Palindrome

2016-11-21
阅读 1 分钟
2k
Longest PalindromeGiven a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.

[Leetcode] Two Sum, 3Sum,4Sum,4SumII,3Sum Closet

2016-11-21
阅读 7 分钟
2.9k
Two SumGiven an array of integers, return indices of the two numbers such that they add up to a specific target.

[LeetCode]Find All Anagrams in a String

2016-11-20
阅读 2 分钟
3.1k
Find All Anagrams in a StringGiven a string s and a non-empty string p, find all the start indices of p's anagrams in s.

[Leetcode]Longest Substring Without Repeating Characters

2016-11-20
阅读 2 分钟
1.9k
Longest Substring Without Repeating CharactersGiven a string, find the length of the longest substring without repeating characters.

[Leetcode-Tree]Sum of Left Leaves

2016-11-20
阅读 2 分钟
2.1k
Sum of Left LeavesFind the sum of all left leaves in a given binary tree.

[Leetcode-Tree] Convert Sorted Array to Binary Search Tree

2016-11-19
阅读 1 分钟
1.6k
Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.

[Leetcode-Tree] Path Sum I II III

2016-11-19
阅读 3 分钟
3.9k
Path SumGiven 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.

Construct Binary Tree from Preorder and Inorder Traversal

2016-11-19
阅读 2 分钟
1.7k
Construct Binary Tree from Preorder and Inorder TraversalGiven preorder and inorder traversal of a tree, construct the binary tree.

[Leetcode-Tree]Delete Node in a BST

2016-11-19
阅读 2 分钟
2.4k
Delete Node in a BSTGiven a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.

[Leetcode-Tree]Maximum / Minimum Depth of Binary Tree

2016-11-19
阅读 1 分钟
1.4k
Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.

[Leetcode-Tree]Binary Tree Level Order Traversal

2016-11-19
阅读 2 分钟
1.4k
Binary Tree Level Order TraversalGiven a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).

[Leetcode-Tree]Binary Tree Maximum Path Sum

2016-11-19
阅读 1 分钟
1.5k
Binary Tree Maximum Path SumGiven a binary tree, find the maximum path sum.

[Leetcode-Tree] Sum Root to Leaf Numbers

2016-11-19
阅读 1 分钟
1.5k
Sum Root to Leaf NumbersGiven a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.

[Leetcode-Dynamic Programming]Unique Binary Search Trees

2016-11-19
阅读 1 分钟
1.5k
Unique Binary Search TreesGiven n, how many structurally unique BST's (binary search trees) that store values 1...n?

[Leetcode-Tree] Kth Smallest Element in a BST

2016-11-18
阅读 2 分钟
1.7k
Kth Smallest Element in a BSTGiven a binary search tree, write a function kthSmallest to find the kth smallest element in it.

[LeetCode-Tree]Binary Tree Inorder & Preorder Traversal

2016-11-18
阅读 3 分钟
1.3k
Binary Tree Inorder TraversalGiven a binary tree, return the inorder traversal of its nodes' values.

[Leetcode - Tree] Binary Search Tree Iterator

2016-11-17
阅读 2 分钟
1.5k
Binary Search Tree IteratorImplement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.

[Leetcode]PermutationsI II Next Permutation Permutation Sequence

2016-11-17
阅读 5 分钟
1.7k
PermutationsGiven a collection of distinct numbers, return all possible permutations.

[LeetCode - Backtracking] Combinations

2016-11-17
阅读 1 分钟
1.9k
CombinationsGiven two integers n and k, return all possible combinations of k numbers out of 1 ... n.

[LeetCode - Dynamic Programming] Coin Change

2016-11-16
阅读 2 分钟
1.9k
Coin ChangeYou are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.

[Leetcode - Array] Combination Sum

2016-11-15
阅读 5 分钟
2.3k
Combination SumGiven a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.

[Leetcode- Dynamic Programming] Best Time to Buy and Sell Stock

2016-11-15
阅读 7 分钟
2k
Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit.

[Leetcode - Dynamic Programming] Partition Equal Subset Sum

2016-11-14
阅读 2 分钟
2.5k
Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.