Skip to content

Commit 319db1e

Browse files
committed
two sum solution
1 parent 9508bce commit 319db1e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

two-sum/ohgyulim.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import java.util.*;
22

33
class Solution {
4+
/* 시간 복잡도: O(N), nums.length를 n이라고 할 때, 시간 복잡도는 O(N)
5+
* - for 루프: O(N)
6+
* - HashMap 연산 (containsKey, put): 평균 O(1)
7+
*
8+
* 공간 복잡도: O(N), HashMap에 최대 n개의 요소를 저장할 수 있음
9+
*/
410
public int[] twoSum(int[] nums, int target) {
511
Map<Integer, Integer> numToIndex = new HashMap<>();
612
for (int i = 0; i < nums.length; i++) {

0 commit comments

Comments
 (0)