This content originally appeared on DEV Community and was authored by duccanhole
--DAY 20--
Hi, I am going to make #100DaysOfCode Challenge. Everyday I will try solve 1 problem from leetcode or hackerrank. Hope you can go with me until end.
Now let's solve problem today:
Problem: Two Sum II
Detail: here
My solution(javascript):
var twoSum = function(numbers, target) {
let i=0,j=numbers.length-1;
while(i<j){
if(numbers[i]+numbers[j]==target){
return [i+1,j+1];
}
else if (numbers[i] + numbers[j] < target)
i++;
else
j--;
}
};
-->If you have better solution or any question, please comment below. I will appreciate.
This content originally appeared on DEV Community and was authored by duccanhole
duccanhole | Sciencx (2021-11-14T07:21:28+00:00) code every day with me. Retrieved from https://www.scien.cx/2021/11/14/code-every-day-with-me-7/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.