ARTS-第25周

ARTS (第25周)

学无止境,一个片段点结束,是下一个片段点开始

Algorithm 算法

###缺失的第一个正数

https://leetcode-cn.com/problems/first-missing-positive/submissions/

给定一个未排序的整数数组,找出其中没有出现的最小的正整数。

示例 1:

输入: [1,2,0]
输出: 3
示例 2:

输入: [3,4,-1,1]
输出: 2
示例 3:

输入: [7,8,9,11,12]
输出: 1

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/first-missing-positive
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//执行用时 : 1 ms , 在所有 Java 提交中击败了 99.71% 的用户
//内存消耗 : 34.8 MB , 在所有 Java 提交中击败了 86.25% 的用户
public static int firstMissingPositive(int[] nums) {
for (int i = 0; i < nums.length; i++) {
int j = nums[i];
if (j > 0 && j < nums.length && j != nums[j - 1]) {
int idx = j - 1;//可能不够放 1放在下标0点位置
// 交换
nums[i] = nums[idx];
nums[idx] = j;
i--;// 继续当前数字
}
}

//System.out.println(Arrays.toString(nums));
for (int i = 0; i < nums.length; i++) {
if (i + 1 != nums[i]) {
return i+1;
}
}
return nums.length + 1;
}

Review 英文文章

https://www.eurekanetwork.org/

eureka的介绍

Tip 技巧

极客时间的专栏《数据结构与算法之美》

本周学习了该专栏中的余下篇章,

如搜索引擎:使用爬虫构建索引来进行快速查找。

Share 分享

https://blog.csdn.net/wzgbgz/article/details/79276341 三句话巧记 23 种设计模式

http://blog.itpub.net/31555484/viewspace-2565387/ sql优化