반응형
○
Dynamic Programming | Easy
119. Pascal's Triangle II
class Solution {
func getRow(_ rowIndex: Int) -> [Int] {
var row = [1]
if rowIndex == 0 { return row }
for i in 1...rowIndex {
var newRow = Array(repeating: 1, count: i + 1)
for j in 1..<i {
newRow[j] = row[j-1] + row[j]
}
row = newRow
}
return row
}
}
728x90
반응형
'Algorithm > LeetCode' 카테고리의 다른 글
[Swift 알고리즘] LeetCode 2399. Check Distances Between Same Letters (0) | 2023.04.25 |
---|---|
[Swift 알고리즘] LeetCode 53. Maximum Subarray (0) | 2023.04.03 |
[Swift 알고리즘] LeetCode 70. Climbing Stairs (0) | 2023.04.03 |
[Swift 알고리즘] LeetCode 118. Pascal's Triangle (0) | 2023.04.01 |
[Swift 알고리즘] LeetCode 2457. Minimum Addition to Make Integer Beautiful (0) | 2023.03.10 |