-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
gocoder
committed
Jan 8, 2019
1 parent
8cbc136
commit ccb02ba
Showing
9 changed files
with
35 additions
and
339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
leetcode.iml | ||
java/java.iml | ||
/.idea/ | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
Solution set for Leetcode online interview problems. | ||
|
||
Code compiled by Java7 | ||
|
||
https://oj.leetcode.com/problems/ |
98 changes: 0 additions & 98 deletions
98
java/com.gocoder.leetcode/BinaryTreeLevelOrderTraversal.java
This file was deleted.
Oops, something went wrong.
100 changes: 0 additions & 100 deletions
100
java/com.gocoder.leetcode/BinaryTreeLevelOrderTraversalII.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.gocoder.leetcode; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
|
||
/** | ||
* 两数之和 | ||
* | ||
* <p>#001 https://leetcode-cn.com/problems/two-sum/ | ||
* | ||
* @author gocoder | ||
*/ | ||
public class L0001 { | ||
|
||
public int[] twoSum(int[] nums, int target) { | ||
int len = nums.length; | ||
HashMap<Integer, Integer> map = new HashMap<>(len); | ||
for (int i = 0; i < len; ++i) { | ||
if (map.containsKey(nums[i])) { | ||
return new int[]{map.get(nums[i]), i}; | ||
} | ||
map.put(target - nums[i], i); | ||
} | ||
return null; | ||
} | ||
|
||
public static void main(String[] args) { | ||
L0001 solution = new L0001(); | ||
int[] nums = new int[]{2, 7, 11, 15}; | ||
int target = 9; | ||
System.out.println(Arrays.toString(solution.twoSum(nums, target))); | ||
} | ||
} |