This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. | |
You should preserve the original relative order of the nodes in each of the two partitions. | |
For example, | |
Given 1->4->3->2->5->2 and x = 3, | |
return 1->2->2->4->3->5. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. | |
Below is one possible representation of s1 = "great": | |
great | |
/ \ | |
gr eat | |
/ \ / \ | |
g r e at | |
/ \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. 括号匹配 | |
给定一堆括号序列,请判断是不是合法的括号序列 | |
()合法 | |
(() 不合法 | |
(())()合法 | |
分析空间和时间 | |
2. | |
Scramble with Friends是一款老少咸宜的益智类游戏 (下载地址:Apple Store Google Play) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given two sorted integer arrays A and B, merge B into A as one sorted array. | |
Note: | |
You may assume that A has enough space to hold additional elements from B. The number of elements initialized in A and B are m and n respectively. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. 青蛙过河 | |
如图所示,河中间有相同间隔的一系列石子,一只小青蛙要从河的左岸跳到右岸去(图中有六只青蛙,题目中只有一只青蛙:( ) 小青蛙可以一次跳一颗石头,也可以一次跳两颗石头,小青蛙只能从左往右跳,请问: 给出河中间石头的颗数,求出小青蛙过河总共有多少种方法 | |
Input: N(1<N<100,000) 石子个数 | |
Output: 过河方法的个数 | |
Time Limit: 1s(C++/Java) | |
Sample Input 1: | |
2 | |
Sample Output 1: | |
3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The gray code is a binary numeral system where two successive values differ in only one bit. | |
Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin with 0. | |
For example, given n = 2, return [0,1,3,2]. Its gray code sequence is: | |
00 - 0 | |
01 - 1 | |
11 - 3 | |
10 - 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A message containing letters from A-Z is being encoded to numbers using the following mapping: | |
'A' -> 1 | |
'B' -> 2 | |
... | |
'Z' -> 26 | |
Given an encoded message containing digits, determine the total number of ways to decode it. | |
For example, | |
Given encoded message "12", it could be decoded as "AB" (1 2) or "L" (12). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given a collection of integers that might contain duplicates, S, return all possible subsets. | |
Note: | |
Elements in a subset must be in non-descending order. | |
The solution set must not contain duplicate subsets. | |
For example, | |
If S = [1,2,2], a solution is: | |
[ | |
[2], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Reverse a linked list from position m to n. Do it in-place and in one-pass. | |
For example: | |
Given 1->2->3->4->5->NULL, m = 2 and n = 4, | |
return 1->4->3->2->5->NULL. | |
Note: | |
Given m, n satisfy the following condition: | |
1 ≤ m ≤ n ≤ length of list. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not matter) |