109. Converted Sorted List to Binary Search Tree

2016-07-10
阅读 1 分钟
1.8k
题目:Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

332. Reconstruct Itinerary

2016-07-10
阅读 3 分钟
2.9k
题目:Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the itinerary must begin with JFK.

207. Course Schedule

2016-07-09
阅读 4 分钟
2.6k
题目:There are a total of n courses you have to take, labeled from 0 to n - 1.

298. Binary Tree Longest Consecutive Sequence

2016-07-07
阅读 2 分钟
2.5k
题目:Given a binary tree, find the length of the longest consecutive sequence path.

337. House RobberIII

2016-07-07
阅读 2 分钟
1.7k
题目:The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour, the smart thief realized that "all houses in this place forms a binary tree". It will aut...

297. Serialize and Deserialize Binary Tree

2016-07-06
阅读 3 分钟
3.4k
题目:Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be reconstructed later in the same or another computer environment.

199. Binary Tree Right Side View

2016-07-05
阅读 1 分钟
2.1k
问题:Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.

117. Populating Next Right Pointers In Each NodeII

2016-07-05
阅读 2 分钟
1.6k
题目:Follow up for problem "Populating Next Right Pointers in Each Node".

99. Recover Binary Search Tree

2016-07-05
阅读 1 分钟
3k
Note:A solution using O(n) space is pretty straight forward. Could you devise a constant space solution?

222. Count Complete Tree Nodes

2016-07-05
阅读 2 分钟
2.1k
Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.

145.Binary Tree Postorder Traversal

2016-07-05
阅读 1 分钟
2.1k
题目:Given a binary tree, return the postorder traversal of its nodes' values.

144. Binary Tree Preorder Traversal

2016-07-04
阅读 2 分钟
2.1k
题目:Given a binary tree, return the preorder traversal of its nodes' values.

166. Fraction to Recurring Decimal

2016-06-29
阅读 2 分钟
2.9k
题目:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format.

94. Binary Tree Inorder Traversal

2016-06-29
阅读 2 分钟
2.8k
题目:Given a binary tree, return the inorder traversal of its nodes' values.

356. Line Reflection

2016-06-29
阅读 1 分钟
4.2k
问题:Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given points.

358. Rearrange String k Distance Apart

2016-06-29
阅读 2 分钟
6.5k
题目:Given a non-empty string str and an integer k, rearrange the string such that the same characters are at least distance k from each other.

249. Group Shifted String

2016-06-29
阅读 2 分钟
5.2k
题目:Given a string, we can "shift" each of its letter to its successive letter, for example: "abc" -> "bcd". We can keep "shifting" which forms the sequence:

159. Longest Substring With At Most Two Distinct Characters

2016-06-29
阅读 1 分钟
2.7k
题目:Given a string, find the length of the longest substring T that contains at most 2 distinct characters.

299. Bulls and Cows

2016-06-28
阅读 3 分钟
2.6k
题目:You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint that indicates how many digits in said guess match your secret number exactly in both digit an...

85. Maximal Rectangel

2016-06-22
阅读 2 分钟
1.8k
题目:Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.

3. Longest Substring Without Repeating Characters

2016-06-22
阅读 3 分钟
2.5k
题目:Given a string, find the length of the longest substring without repeating characters.

1. Two Sum

2016-06-22
阅读 2 分钟
2.1k
问题:Given an array of integers, return indices of the two numbers such that they add up to a specific target.

49. Group Anagrams

2016-06-22
阅读 2 分钟
3k
For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:

164. Maximum Gap

2016-06-22
阅读 2 分钟
3.7k
题目:Given an unsorted array, find the maximum difference between the successive elements in its sorted form.

274. H-Index

2016-06-22
阅读 3 分钟
2.3k
题目:Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher's h-index.

75. Sort Colors

2016-06-21
阅读 2 分钟
2.8k
题目:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.

147. Insertion Sort List

2016-06-21
阅读 1 分钟
2.6k
注意新的list跟原来的list是不相连的,然后把各个状态的点记录好就行: {代码...}

179. Largest Number

2016-06-21
阅读 1 分钟
2.1k
这道题开始想容易陷入一个误区:我要怎么比较这两个单独的数,使得它们拼起来的结果最大呢?然而如果真的仔细比较这两个数最后得出一个结论,代码会很长,楼主已经试过了。。。后来转念一想,直接比较两个数拼成的结果不就好了,长度一样,所以省去了很多麻烦。程序如下:

Sorting

2016-06-20
阅读 6 分钟
2.2k
Bubble Sort就不说了,下面简单总结一个Selection Sort, Insertion Sort, Merge Sort和Quick Sort:

148. Sort List

2016-06-20
阅读 2 分钟
3.3k
题目:Sort a linked list in O(n log n) time using constant space complexity.