code every day with me

–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(javas…


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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » code every day with me." duccanhole | Sciencx - Sunday November 14, 2021, https://www.scien.cx/2021/11/14/code-every-day-with-me-7/
HARVARD
duccanhole | Sciencx Sunday November 14, 2021 » code every day with me., viewed ,<https://www.scien.cx/2021/11/14/code-every-day-with-me-7/>
VANCOUVER
duccanhole | Sciencx - » code every day with me. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/14/code-every-day-with-me-7/
CHICAGO
" » code every day with me." duccanhole | Sciencx - Accessed . https://www.scien.cx/2021/11/14/code-every-day-with-me-7/
IEEE
" » code every day with me." duccanhole | Sciencx [Online]. Available: https://www.scien.cx/2021/11/14/code-every-day-with-me-7/. [Accessed: ]
rf:citation
» code every day with me | duccanhole | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.