Last active
July 17, 2019 19:13
-
-
Save vikmeup/e38203a4397674e25dae01ab2dc108f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func generate(numRows: Int) -> [[Int]] { | |
var results = [[Int]]() | |
if (numRows == 0) { | |
return results | |
} | |
for i in 0..<numRows { | |
var currentResults = [Int]() | |
for j in 0...i { | |
if (i > 1 && j > 0 && j < i) { | |
let value = results[i-1][j] + results[i-1][j-1] | |
currentResults.append(value) | |
} else { | |
currentResults.append(1) | |
} | |
} | |
results.append(currentResults) | |
} | |
return results | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment