Skip to content

Commit 0d0db5c

Browse files
committed
add leetcode
1 parent 52a824d commit 0d0db5c

4 files changed

Lines changed: 74 additions & 3 deletions

File tree

.idea/compiler.xml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
- 深入理解 Mybatis
7575

7676
# 记录
77+
78+
## 5.27
79+
> I'm back.
80+
7781
## 5.9
7882
> 最近在搞大作业,佛性更新进度
7983

java_test/src/main/java/com/yiyun/JustTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.yiyun;
22

3+
import org.junit.Test;
4+
35
public class JustTest {
46
{
57
System.out.println("a.....");
@@ -18,4 +20,9 @@ public static void main(String[] args) {
1820
int i = Runtime.getRuntime().availableProcessors();
1921
System.out.println("i = " + i);
2022
}
23+
@Test
24+
public void fun(){
25+
int i = ((6-3) >> 1 )+3;
26+
System.out.println("i = " + i);
27+
}
2128
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package leetcode;
2+
3+
import org.junit.Test;
4+
5+
public class LC_287 {
6+
public int findDuplicate(int[] nums) {
7+
int fast=0,slow=0;
8+
while (true){
9+
fast=nums[nums[fast]];
10+
slow=nums[slow];
11+
if (fast==slow){
12+
fast=0;
13+
while (nums[fast]!=nums[slow]){
14+
fast=nums[fast];
15+
slow=nums[slow];
16+
}
17+
return nums[slow];
18+
}
19+
}
20+
}
21+
public int findDuplicate2(int[] nums) {
22+
int start=1;
23+
int end=nums.length-1;
24+
while (start<=end){
25+
int mid=((end-start)>>1)+start;
26+
int cntRange = cntRange(nums, start, mid);
27+
if (start==end){
28+
if (cntRange>1){
29+
return start;
30+
}else {
31+
break;
32+
}
33+
}
34+
if (cntRange>mid-start+1){
35+
end=mid;
36+
}else {
37+
start=mid+1;
38+
}
39+
}
40+
return -1;
41+
}
42+
private int cntRange(int[] nums,int start,int end){
43+
int cnt=0;
44+
for (int i = 0; i < nums.length; i++) {
45+
if (nums[i]>=start&&nums[i]<=end){
46+
cnt++;
47+
}
48+
}
49+
return cnt;
50+
}
51+
52+
53+
@Test
54+
public void fun(){
55+
int[] ints = {3,1,4,3,2};
56+
// int duplicate = findDuplicate(ints);
57+
int duplicate = findDuplicate2(ints);
58+
System.out.println("duplicate = " + duplicate);
59+
}
60+
}

0 commit comments

Comments
 (0)