Skip to content

Commit 795364d

Browse files
committed
leetcode 1
0 parents  commit 795364d

File tree

8 files changed

+115
-0
lines changed

8 files changed

+115
-0
lines changed

.gitignore

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### IntelliJ IDEA ###
2+
out/
3+
!**/src/main/**/out/
4+
!**/src/test/**/out/
5+
6+
### Eclipse ###
7+
.apt_generated
8+
.classpath
9+
.factorypath
10+
.project
11+
.settings
12+
.springBeans
13+
.sts4-cache
14+
bin/
15+
!**/src/main/**/bin/
16+
!**/src/test/**/bin/
17+
18+
### NetBeans ###
19+
/nbproject/private/
20+
/nbbuild/
21+
/dist/
22+
/nbdist/
23+
/.nb-gradle/
24+
25+
### VS Code ###
26+
.vscode/
27+
28+
### Mac OS ###
29+
.DS_Store

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LeetCodeJava.iml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

src/Main.java

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//TIP 要<b>运行</b>代码,请按 <shortcut actionId="Run"/> 或
2+
// 点击装订区域中的 <icon src="AllIcons.Actions.Execute"/> 图标。
3+
public class Main {
4+
public static void main(String[] args) {
5+
//TIP 当文本光标位于高亮显示的文本处时按 <shortcut actionId="ShowIntentionActions"/>
6+
// 查看 IntelliJ IDEA 建议如何修正。
7+
System.out.printf("Hello and welcome!");
8+
9+
for (int i = 1; i <= 5; i++) {
10+
//TIP 按 <shortcut actionId="Debug"/> 开始调试代码。我们已经设置了一个 <icon src="AllIcons.Debugger.Db_set_breakpoint"/> 断点
11+
// 但您始终可以通过按 <shortcut actionId="ToggleLineBreakpoint"/> 添加更多断点。
12+
System.out.println("i = " + i);
13+
}
14+
}
15+
}

src/leetcode1/Main.java

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package leetcode1;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class Main {
7+
public static void main(String[] args){
8+
int[] nums = new int[]{2,7,11,15};
9+
10+
int target = 9;
11+
12+
int[] map = twoSum(nums,target);
13+
for (int i:map){
14+
System.out.println(i);
15+
}
16+
17+
18+
19+
}
20+
21+
public static int[] twoSum(int[] nums,int target){
22+
Map<Integer,Integer> map = new HashMap<>();
23+
for(int i=0;i<nums.length;i++){
24+
if(map.containsKey(target-nums[i])){
25+
return new int[]{map.get(target-nums[i]),i};
26+
}else{
27+
map.put(nums[i],i);
28+
}
29+
}
30+
throw new IllegalArgumentException("No two sum solution");
31+
}
32+
}

0 commit comments

Comments
 (0)