DAY 13
0

## 題目:

https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/

## 解題思路:

### C版本:

``````int* twoSum(int* numbers, int numbersSize, int target, int* returnSize) {
int *reval = (int*)malloc(sizeof(int)*2);
*returnSize = 2;

int left, right;
left = 0; right = numbersSize-1;
for(;;) {
if(numbers[left] + numbers[right] > target)
right--;
else if(numbers[left] + numbers[right] < target)
left++;
else {
reval[0] = left+1;
reval[1] = right+1;
return reval;
}
}
}
``````

### Javascript版本:

``````var twoSum = function(numbers, target) {
var result = [];
for(var i = 0; i<numbers.length; i++)
{
for(var j = i+1; j<numbers.length; j++)
{
if((numbers[i] + numbers[j]) == target)
{
result.push(i+1)
result.push(j+1)
return result;
}
}
}
};
``````

## 程式Github分享:

https://github.com/SIAOYUCHEN/leetcode

## 本日分享:

Every time you encounter frustration, when you meet people who laugh at you and hit you, please tell yourself you can’t borrow their wings and fly to the sky you want to go, just like they can’t replace you that living a life you don’t want.