Problem
- Link
- Description
- Target 숫자가 되는 숫자 2개의 합을 찾아서 반환
- Type
Solution 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| class Solution {
public int[] twoSum(int[] nums, int target) {
int i = 0, j = 0;
loop:
for (i = 0; i < nums.length; i++) {
for (j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] == target) {
break loop;
}
}
}
return new int[] {i, j};
}
}
|
Solution 1
- Description
- Time Complexity
- O(len(nums)^2)
- len(nums)의 크기만큼 두번의 중복 for Loop 수행
- Space Complexity
- O(len(nums))
- 함수의 입력값으로 len(nums)의 크기 만큼 Memory 이용