File tree Expand file tree Collapse file tree 1 file changed +16
-17
lines changed Expand file tree Collapse file tree 1 file changed +16
-17
lines changed Original file line number Diff line number Diff line change 1- package week01 .twosum ;
2-
31import java .util .HashMap ;
42import java .util .Map ;
3+ /*
4+ 시간복잡도: O(n)
5+ 공간복잡도: O(n)
6+ */
57
6- public class JEONGBEOMKO {
7-
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 );
13- }
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 );
13+ }
1414
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- }
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 };
2019 }
21-
22- return new int [] {};
2320 }
21+
22+ return new int [] {};
2423 }
2524}
You can’t perform that action at this time.
0 commit comments