File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed
_includes/_root/two-sum-iii-data-structure-design
two-sum-iii-data-structure-design Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
---
2
2
layout : solution
3
3
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
5
5
---
6
6
{% assign leetcode_name = {{page.path | remove: '/index.md'}} %}
7
7
{% assign leetcode_readme = {{leetcode_name | append: '/README.md' | prepend: '_ root/' }} %}
You can’t perform that action at this time.
0 commit comments