技术自留地


  • 首页

  • 标签

  • 分类

  • 归档

  • 搜索

33. Search in Rotated Sorted Array

发表于 2017-10-16 | 分类于 LeetCode

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.

(i.e., 0 1 2 4 5 6 7 might become 4 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

发表于 2017-10-16 | 分类于 LeetCode

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.

题意表述异常简练:合并多个有序链表

阅读全文 »

22. Generate Parentheses

发表于 2017-10-16 | 分类于 LeetCode

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

发表于 2017-10-16 | 分类于 LeetCode

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

发表于 2017-10-16 | 分类于 LeetCode

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

发表于 2017-10-16 | 分类于 LeetCode

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

发表于 2017-10-16 | 分类于 LeetCode

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

发表于 2017-10-16 | 分类于 LeetCode

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

发表于 2017-10-16 | 分类于 LeetCode

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

发表于 2017-10-16 | 分类于 LeetCode

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].
> >
>
阅读全文 »
1…456
chaopengz

chaopengz

北航|北大|码农|图形学

56 日志
12 分类
15 标签
© 2021 chaopengz
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.3