Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e.,
0 1 2 4 5 6 7might become4 5 6 7 0 1 2).You are given a target value to search. If found in the array return its index, otherwise return -1.
You may assume no duplicate exists in the array.
23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
题意表述异常简练:合并多个有序链表
22. Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
For example, given n = 3, a solution set is:
1
2
3
4
5
6
7
8 > [
> "((()))",
> "(()())",
> "(())()",
> "()(())",
> "()()()"
> ]
>
19. Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head.
For example,
1
2
3
4 > Given linked list: 1->2->3->4->5, and n = 2.
>
> After removing the second node from the end, the linked list becomes 1->2->3->5.
>
>
Note:
Given n will always be valid.
Try to do this in one pass.
15. 3Sum
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.
Note: The solution set must not contain duplicate triplets.
1
2
3
4
5
6
7
8
9
10 > > For example, given array S = [-1, 0, 1, 2, -1, -4],
> >
> > A solution set is:
> > [
> > [-1, 0, 1],
> > [-1, -1, 2]
> > ]
> >
>
>
11. Container With Most Water
Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
Note: You may not slant the container and n is at least 2.
5. Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.
Example:
1
2
3
4
5
6
7 > Input: "babad"
>
> Output: "bab"
>
> Note: "aba" is also a valid answer.
>
>Example:
1
2
3
4 > Input: "cbbd"
>
> Output: "bb"
>
3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given
"abcabcbb", the answer is"abc", which the length is 3.Given
"bbbbb", the answer is"b", with the length of 1.Given
"pwwkew", the answer is"wke", with the length of 3. Note that the answer must be a substring,"pwke"is a subsequenceand not a substring.
2. Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
1. Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
1
2
3
4
5
6 > > Given nums = [2, 7, 11, 15], target = 9,
> >
> > Because nums[0] + nums[1] = 2 + 7 = 9,
> > return [0, 1].
> >
>