Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/* I can use two pointers to make this happen, The ith entry of the row contains 'i' elements the first and last entries of the list is '1' 1 -> 1 2 -> 2 3 -> 3 4 -> 4 */ class Solution { public: vector
> generate(int numRows) { // Create the triangle vector
> pascal; // Iterate over the triangle to fill it for(int k = 0; k < numRows; k++) { // Create a new row, with first and last entry as 1 vector
row = vector
(k+1, 1); // push the row pascal.emplace_back(row); // If length is greater than 2 if(k >= 2) { // Use two pointers to fill the array, // left will start for the 0th index, right will go upto the last index int l = 0, r = 1; while(r != k) { pascal[k][l+1] = pascal[k-1][l] + pascal[k-1][r]; l++; r++; } } } return pascal; } };
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)