code every day with me

–DAY 16–

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: Pascal’s Triangle II (read more about i…


This content originally appeared on DEV Community and was authored by duccanhole

--DAY 16--

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: Pascal's Triangle II (read more about it here)
  • Detail: here
  • My solution (javascript):
var getRow = function(index) {
    if(index==0) return [1];
    if(index==1) return [1,1];
    let ans=[[1],[1,1]];
    for(let i=2;i<=index;i++){
        let tmp=[];
        tmp[0]=1;
        for(let j=1;j<i+1;j++){
            tmp[j]=ans[i-1][j-1]+ans[i-1][j];
        }
        tmp[i]=1;
        ans.push(tmp);
    }
    return ans[index];
};

-->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-10T01:36:51+00:00) code every day with me. Retrieved from https://www.scien.cx/2021/11/10/code-every-day-with-me-4/

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

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.