Skip to content

Commit 4fffc85

Browse files
committed
add two sum iii
1 parent f6060b7 commit 4fffc85

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

_includes/_root/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+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: solution
33
title: Two Sum III - Data structure design
4-
date: 2014-12-26 18:07:43+08:00
4+
date: 2014-12-26 18:08:59 +0800
55
---
66
{% assign leetcode_name = {{page.path | remove: '/index.md'}} %}
77
{% assign leetcode_readme = {{leetcode_name | append: '/README.md' | prepend: '_root/' }} %}

0 commit comments

Comments
 (0)