Pascal Row
JavaScript
Medium
2 views
Problem Description
Given n (0-based), print n-th row of Pascal triangle (space separated).
Input Format
One integer n.
Output Format
One line of n+1 integers.
Official Solution
const fs=require('fs');const s=fs.readFileSync(0,'utf8').trim();if(!s)process.exit(0);const n=Number(s);let row=[1n];for(let i=1;i<=n;i++){let next=[1n];for(let j=1;j<i;j++)next.push(row[j-1]+row[j]);next.push(1n);row=next;}process.stdout.write(row.map(v=>v.toString()).join(' '));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!