File tree Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Expand file tree Collapse file tree 1 file changed +17
-12
lines changed Original file line number Diff line number Diff line change 1+ package week01 .twosum ;
2+
13import java .util .HashMap ;
24import java .util .Map ;
35
4- class Solution {
5- public int [] twoSum (int [] nums , int target ) {
6- Map <Integer , Integer > numberMap = new HashMap <>();
7- for (int i =0 ; i <nums .length ; i ++) {
8- numberMap .put (nums [i ], i );
9- }
6+ public class JEONGBEOMKO {
107
11- for (int i =0 ; i <nums .length ; i ++) {
12- int operand = target - nums [i ];
13- if (numberMap .containsKey (operand ) && numberMap .get (operand ) != i ) { // ์๊ธฐ ์์ ์ ์ ์ธ
14- return new int [] { numberMap .get (target - nums [i ]), i };
8+ class Solution {
9+ public int [] twoSum (int [] nums , int target ) {
10+ Map <Integer , Integer > numberMap = new HashMap <>();
11+ for (int i =0 ; i <nums .length ; i ++) {
12+ numberMap .put (nums [i ], i );
1513 }
16- }
1714
18- return new int [] {};
15+ for (int i =0 ; i <nums .length ; i ++) {
16+ int operand = target - nums [i ];
17+ if (numberMap .containsKey (operand ) && numberMap .get (operand ) != i ) { // ์๊ธฐ ์์ ์ ์ ์ธ
18+ return new int [] { numberMap .get (target - nums [i ]), i };
19+ }
20+ }
21+
22+ return new int [] {};
23+ }
1924 }
2025}
You canโt perform that action at this time.
0 commit comments