File tree 2 files changed +28
-1
lines changed
src/main/java/com/leetcode
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 5
5
import java .util .function .BiConsumer ;
6
6
import java .util .List ;
7
7
8
- public class ArrayOne {
8
+ public class DisappearedNumber {
9
9
/**
10
10
*
11
11
* find the disappeared numbers in array
Original file line number Diff line number Diff line change
1
+ package com .leetcode .hash ;
2
+
3
+ import java .util .HashMap ;
4
+ import java .util .Map ;
5
+
6
+ public class TwoSumS {
7
+
8
+ public int [] twoSun (int [] nums , int target ){
9
+ Map <Integer , Integer > map = new HashMap <>();
10
+ for (int i = 0 ; i < nums .length ; i ++) {
11
+ if (map .containsKey (target -nums [i ])) {
12
+ return new int []{i , map .get (target -nums [i ])};
13
+ }
14
+ map .put (nums [i ], i );
15
+ }
16
+ return new int []{};
17
+ }
18
+
19
+ public static void main (String [] args ) {
20
+ int [] arr = {2 ,5 ,7 ,9 };
21
+ int [] ints = new TwoSumS ().twoSun (arr , 7 );
22
+ for (int i : ints ){
23
+ System .out .println (i );
24
+ }
25
+
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments