leetcode

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 710523a934fae5f7c09aa93147081be4bad87c7a
parent 6ac531cbbe54bb63d7e644f849a200f93b792df5
Author: AndrewLockVI <andrewlaack1@gmail.com>
Date:   Mon, 15 May 2023 10:33:07 -0500

Completed pascals triangle ii problem

Diffstat:
Apascals-triangle-ii/pascals-triangle-ii.dart | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)

diff --git a/pascals-triangle-ii/pascals-triangle-ii.dart b/pascals-triangle-ii/pascals-triangle-ii.dart @@ -0,0 +1,22 @@ +//Given a zero indexed row of pascal's triangle return +//the values in that row. I solved this using DP and recursion +//to find the first row then second and so on until returning the requested row. +//The time complexity of this is O(n^2). +//Time: 260ms Beats: 63.64% +//Memory: 140.7MB Beats: 36.36% + +class Solution { + List<int> getRow(int rowIndex) { + if(rowIndex <= 0){ + return [1]; + } + List<int> last_row = getRow(rowIndex - 1); + List<int> this_row = []; + this_row.add(1); + for(int i = 1 ; i < last_row.length ; ++i){ + this_row.add(last_row[i-1] + last_row[i]); + } + this_row.add(1); + return this_row; + } +}