Skip to content

Commit

Permalink
update #001 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
gocoder committed Jan 8, 2019
1 parent 8cbc136 commit ccb02ba
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 339 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
leetcode.iml
java/java.iml
/.idea/
/bin/
2 changes: 0 additions & 2 deletions README.md
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 java/com.gocoder.leetcode/BinaryTreeLevelOrderTraversal.java

This file was deleted.

100 changes: 0 additions & 100 deletions java/com.gocoder.leetcode/BinaryTreeLevelOrderTraversalII.java

This file was deleted.

35 changes: 0 additions & 35 deletions java/com.gocoder.leetcode/CountAndSay.java

This file was deleted.

41 changes: 0 additions & 41 deletions java/com.gocoder.leetcode/PascalTriangle.java

This file was deleted.

28 changes: 0 additions & 28 deletions java/com.gocoder.leetcode/PascalTriangleII.java

This file was deleted.

34 changes: 0 additions & 34 deletions java/com.gocoder.leetcode/ReverseInteger.java

This file was deleted.

33 changes: 33 additions & 0 deletions src/com/gocoder/leetcode/L0001.java
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)));
}
}

0 comments on commit ccb02ba

Please sign in to comment.