Skip to content

Instantly share code, notes, and snippets.

@vikmeup
Last active July 17, 2019 19:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vikmeup/e38203a4397674e25dae01ab2dc108f2 to your computer and use it in GitHub Desktop.
Save vikmeup/e38203a4397674e25dae01ab2dc108f2 to your computer and use it in GitHub Desktop.
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