This content originally appeared on DEV Community and was authored by duccanhole
--DAY 14--
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
- Detail: here
- My solution (javascript):
var generate = function(n) {
if(n==1) return [[1]];
if(n==2) return [[1],[1,1]];
let arr=[[1],[1,1]];
for(let i=2;i<n;i++){
arr[i]=[1];
for(let j=1;j<i;j++){
arr[i].push(arr[i-1][j-1]+arr[i-1][j]);
}
arr[i].push(1);
}
return arr;
};
This content originally appeared on DEV Community and was authored by duccanhole

duccanhole | Sciencx (2021-11-03T08:01:22+00:00) code every day with me. Retrieved from https://www.scien.cx/2021/11/03/code-every-day-with-me-3/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.