类别归档:LeetCode

LeetCode OJ is a platform for preparing technical coding interviews.

RSS feed of LeetCode

[LeetCode]First Missing Positive

题目描述:

Given an unsorted integer array, find the first missing positive integer.

For example,
Given [1,2,0] return 3,
and [3,4,-1,1] return 2.

Your algorithm should run in O(n) time and uses constant space.

题目大意:

给定一个未经排序的数组,寻找第一个缺失的正整数。

例如,
给定 [1,2,0] 返回3,
给定 ...

继续阅读

[LeetCode]H-Index II

题目描述:

Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?

Hint:

Expected runtime complexity is in O(log n) and the input is sorted.

题目大意:

H-Index的延伸:如果引用数组是递增有序的,你应该怎样优化算法?

提示:

期望运行时间复杂度为O(log n),并且输入是递增有序的。

解题思路:

二分法(Binary ...

继续阅读