Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit20dcf42

Browse files
author
wayne
committed
添加二分查找
1 parentf1116fc commit20dcf42

File tree

8 files changed

+204
-0
lines changed

8 files changed

+204
-0
lines changed

‎binary/.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store

‎binary/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectxmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.example</groupId>
8+
<artifactId>learn-algorithm</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<groupId>com.flydean</groupId>
13+
<artifactId>binary</artifactId>
14+
15+
<properties>
16+
<maven.compiler.source>17</maven.compiler.source>
17+
<maven.compiler.target>17</maven.compiler.target>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
</properties>
20+
21+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
packagecom.flydean;
2+
3+
4+
publicclassBinaryTest {
5+
6+
publicstaticvoidmain(String[]args) {
7+
inta =100;
8+
intb =212;
9+
System.out.println(a^b);
10+
Integer.reverse(122);
11+
Integer.bitCount(112);
12+
}
13+
}

‎binarySearch/.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store

‎binarySearch/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectxmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.example</groupId>
8+
<artifactId>learn-algorithm</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<groupId>com.flydean</groupId>
13+
<artifactId>binarySearch</artifactId>
14+
15+
<properties>
16+
<maven.compiler.source>17</maven.compiler.source>
17+
<maven.compiler.target>17</maven.compiler.target>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
</properties>
20+
21+
</project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
packagecom.flydean;
2+
3+
publicclassBinarySearch {
4+
5+
publicstaticvoidmain(String[]args) {
6+
int[]nums =newint[]{1,3,3,3,5};
7+
BinarySearchbs =newBinarySearch();
8+
System.out.println(bs.searchInsertLeftMost(nums,2));
9+
System.out.println(bs.searchInsertRightMost(nums,3));
10+
}
11+
12+
publicintsearchInsertLeftMost(int[]nums,inttarget) {
13+
intleft=0;
14+
intright =nums.length-1;
15+
while(left <=right){
16+
intmid=(left+right)/2;
17+
if(nums[mid]<target){
18+
left=mid+1;
19+
}else{
20+
right=mid-1;
21+
}
22+
}
23+
System.out.println(left+":"+right);
24+
returnleft;
25+
}
26+
27+
publicintsearchInsertRightMost(int[]nums,inttarget) {
28+
intleft=0;
29+
intright =nums.length-1;
30+
while(left <=right){
31+
intmid=(left+right)/2;
32+
if(nums[mid]<=target){
33+
left=mid+1;
34+
}else{
35+
right=mid-1;
36+
}
37+
38+
}
39+
System.out.println(left+":"+right);
40+
returnright;
41+
}
42+
43+
44+
}

‎pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
<module>recursion</module>
2222
<module>trie</module>
2323
<module>array</module>
24+
<module>binarySearch</module>
25+
<module>binarySearch</module>
26+
<module>binarySearch</module>
27+
<module>binary</module>
2428
</modules>
2529

2630
<dependencies>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
packagecom.flydean;
2+
3+
importjava.util.PriorityQueue;
4+
5+
publicclassPriorityQueueTest {
6+
7+
publicstaticvoidmain(String[]args) {
8+
PriorityQueuequeMin =newPriorityQueue<Integer>((a,b) -> (b -a));
9+
PriorityQueuequeMax =newPriorityQueue<Integer>((a,b) -> (a -b));
10+
11+
queMin.offer(1);
12+
queMin.offer(2);
13+
System.out.println(queMin.peek());
14+
System.out.println(queMin.poll());
15+
16+
queMax.offer(1);
17+
queMax.offer(2);
18+
System.out.println(queMax.peek());
19+
System.out.println(queMax.poll());
20+
21+
22+
23+
24+
}
25+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp