ZMR小站

很高兴遇见你~


  • 首页

  • 标签

  • 分类

  • 归档

p15

发表于 2016-08-04 | 分类于 blog

LeetCode 15 3Sum 题解

1.题目:

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.
For example, given array S = [-1, 0, 1, 2, -1, -4],
A solution set is:
[
[-1, 0, 1],
[-1, -1, 2]
]

阅读全文 »

p1

发表于 2016-08-03 | 分类于 blog

LeetCode 1 Two Sum 题解

1.题目:

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.
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].

阅读全文 »

p128

发表于 2016-08-03 | 分类于 blog

LeetCode 128 Longest Consecutive Sequence 题解

1.题目:

Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
For example,
Given [100, 4, 200, 1, 3, 2],
The longest consecutive elements sequence is [1, 2, 3, 4]. Return its length: 4.
Your algorithm should run in O(n) complexity.
Subscribe to see which companies asked this question

阅读全文 »

p81

发表于 2016-08-02 | 分类于 blog

LeetCode 81 Search in Rotated Sorted Array II 题解

1.题目:

Follow up for “Search in Rotated Sorted Array”:
What if duplicates are allowed?
Would this affect the run-time complexity? How and why?
Write a function to determine if a given target is in the array.

阅读全文 »

p33

发表于 2016-08-02 | 分类于 blog

LeetCode 33 Search in Rotated Sorted Array 题解

1.题目:

Suppose a sorted array 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.
Subscribe to see which companies asked this question

阅读全文 »

p80

发表于 2016-08-02 | 分类于 blog

LeetCode 80 Remove Duplicates from Sorted Array II 题解

1.题目:

Follow up for “Remove Duplicates”:
What if duplicates are allowed at most twice?
For example,
Given sorted array nums = [1,1,1,2,2,3],
Your function should return length = 5, with the first five elements of nums being 1, 1, 2, 2 and 3. It doesn’t matter what you leave beyond the new length.
Subscribe to see which companies asked this question

阅读全文 »

p26

发表于 2016-08-02 | 分类于 blog

LeetCode 26 Remove Duplicates from Sorted Array 题解

1.题目:

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
For example,
Given input array nums = [1,1,2],
Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively. It doesn’t matter what you leave beyond the new length.
Subscribe to see which companies asked this question

阅读全文 »
1…262728…33
ZhangMengRou

ZhangMengRou

ZMR小站

230 日志
4 分类
14 标签
© 2019 ZhangMengRou
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.4