forked from javadev/LeetCode-in-Kotlin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSolution.kt
24 lines (22 loc) · 858 Bytes
/
Solution.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package g0101_0200.s0118_pascals_triangle
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming
// #Data_Structure_I_Day_4_Array #Dynamic_Programming_I_Day_12 #Udemy_Dynamic_Programming
// #2022_10_08_Time_277_ms_(33.22%)_Space_34.2_MB_(90.60%)
class Solution {
fun generate(numRows: Int): List<List<Int>> {
val output: MutableList<List<Int>> = ArrayList()
for (i in 0 until numRows) {
val currRow: MutableList<Int> = ArrayList()
for (j in 0..i) {
if (j == 0 || j == i || i <= 1) {
currRow.add(1)
} else {
val currCell = output[i - 1][j - 1] + output[i - 1][j]
currRow.add(currCell)
}
}
output.add(currRow)
}
return output
}
}