반응형
leetcode.com/problems/two-sum/
solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
/**
* Note: The returned array must be malloced, assume caller calls free().
*/
int* twoSum(int* nums, int numsSize, int target, int* returnSize) {
*returnSize = 2;
int* rstAry = (int*)malloc(sizeof(int) * 2);
for (int i = 0; i < numsSize; i++) {
for (int j = i+1; j < numsSize; j++) {
if (nums[i] + nums[j] == target) {
rstAry[0] = i;
rstAry[1] = j;
return rstAry;
}
}
}
return rstAry;
}
|
cs |
반응형
'코딩테스트 > Leetcode' 카테고리의 다른 글
Leetcode - [Easy]13. Roman to Integer (0) | 2021.03.14 |
---|---|
Leetcode - [Medium]3. Longest Substring Without Repeating Characters (0) | 2021.03.07 |
Leetcode - [Medium]2. Add Two Numbers (0) | 2021.03.04 |
Leetcode - [Easy]9. Palindrome Number (0) | 2021.03.04 |
Leetcode - [Easy]7. Reverse Integer (0) | 2021.03.04 |