Skip to content

Commit f6060b7

Browse files
committed
add two sum iii
1 parent c7e8401 commit f6060b7

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

two-sum-iii-data-structure-design/README.md

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
public class TwoSum {
2+
3+
Map<Integer, Integer> nums = new HashMap<Integer, Integer>();
4+
5+
public void add(int number) {
6+
Integer c = nums.get(number);
7+
if(c == null) c = 0;
8+
c++;
9+
10+
nums.put(number, c);
11+
}
12+
13+
public boolean find(int value) {
14+
15+
for(Integer n : nums.keySet()){
16+
Integer c = nums.get(value - n);
17+
18+
if(c == null) continue;
19+
20+
if(value - n == n){
21+
if(c > 1){
22+
return true;
23+
}
24+
}else{
25+
return true;
26+
}
27+
}
28+
29+
30+
return false;
31+
}
32+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Solution.java
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
layout: solution
3+
title: Two Sum III - Data structure design
4+
date: 2014-12-26 18:07:43+08:00
5+
---
6+
{% assign leetcode_name = {{page.path | remove: '/index.md'}} %}
7+
{% assign leetcode_readme = {{leetcode_name | append: '/README.md' | prepend: '_root/' }} %}
8+
{% include {{leetcode_readme}} %}

0 commit comments

Comments
 (0)