Skip to content

Commit c9ddec8

Browse files
committed
知识体系
1 parent 9948713 commit c9ddec8

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
- 分布式集群下如何做到唯一序列号。
156156
- 设计一个秒杀系统,30分钟没付款就自动关闭交易。
157157
- [如何使用redis和zookeeper实现分布式锁?有什么区别优缺点,会有什么问题,分别适用什么场景。](https://mp.weixin.qq.com/s/OCIg3TwpmXzqOVqBZ2fSow)
158+
- [基于Zookeeper的分布式锁](https://blog.csdn.net/qiangcuo6087/article/details/79067136)
158159
- [如果知道redlock,讲讲他的算法实现](http://www.redis.cn/topics/distlock.html)
159160
- [分布式事务的原理,优缺点,如何使用分布式事务,2pc 3pc 的区别,解决了哪些问题,还有哪些问题没解决,如何解决,你自己项目里涉及到分布式事务是怎么处理的。](https://www.jianshu.com/p/16b1baf015e8)
160161
- [什么是一致性hash。](https://www.cnblogs.com/lpfuture/p/5796398.html)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.algorithm.study.demo.algorithm;
2+
3+
import com.sun.javadoc.SeeTag;
4+
5+
import java.util.*;
6+
7+
public class ArrayProject {
8+
public static void main(String[] args) {
9+
ArrayProject p=new ArrayProject();
10+
11+
System.out.println(p.containsDuplicate(new int[]{1,2,3,1}));
12+
}
13+
14+
/***
15+
* 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标。
16+
* 你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。
17+
*
18+
* 示例:
19+
* 给定 nums = [2, 7, 11, 15], target = 9
20+
* 因为 nums[0] + nums[1] = 2 + 7
21+
*/
22+
public int[] twoSum(int[] nums, int target) {
23+
if (nums.length==0){
24+
return new int[]{};
25+
}
26+
Map<Integer,Integer> map=new HashMap();
27+
for(int i=0;i<nums.length;i++){
28+
int temp=target-nums[i];
29+
if(map.containsKey(temp)){
30+
return new int[]{map.get(temp),i};
31+
}
32+
map.put(nums[i],i);
33+
}
34+
return new int[]{};
35+
}
36+
37+
/**
38+
* 给定一个整数数组,判断是否存在重复元素。
39+
* 如果任何值在数组中出现至少两次,函数返回 true。如果数组中每个元素都不相同,则返回 false。
40+
* 示例 1:
41+
* 输入: [1,2,3,1]
42+
* 输出: true
43+
*/
44+
public boolean containsDuplicate(int[] nums) {
45+
if (nums.length==0 || nums.length==1){
46+
return true;
47+
}
48+
Set<Integer> set=new HashSet<>();
49+
for (int i=0;i<nums.length;i++){
50+
set.add(nums[i]);
51+
}
52+
if (set.size()!=nums.length){
53+
return true;
54+
}
55+
return false;
56+
}
57+
}

0 commit comments

Comments
 (0)