对于快速排序过程中一个的问题:为什么在qsort中递归时,需要将递归范围改为[lo, pos-1]而不是[lo, pos]?
221.Maximal Square
Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.
单调序列
- Monotonic Array
An array is monotonic if it is either monotone increasing or monotone decreasing.
An array A
is monotone increasing if for all i <= j
, A[i] <= A[j]
. An array A
is monotone decreasing if for all i <= j
, A[i] >= A[j]
.
Return true
if and only if the given array A
is monotonic.
从数组中找重复数字系列
287. Find the Duplicate Number
- 方法一:排序,将整个数组进行排序.排序的时间复杂度和空间复杂度取决于使用的排序算法.
这里要求额外空间排序度为O(1),那么只能用堆排序. - 方法二:使用set
- 方法三
- 前面方法一都会修改数组,不满足要求.方法二的额外空间复杂度是O(n),同样不满足要求.
- https://leetcode.com/problems/find-the-duplicate-number/
142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null
.
To represent a cycle in the given linked list, we use an integer pos
which represents the position (0-indexed) in the linked list where tail connects to. If pos
is -1
, then there is no cycle in the linked list.
Note: Do not modify the linked list.