My Simple and Short Swift Solution


  • 0
    Y
    func getRow(_ rowIndex: Int) -> [Int] {
        var ans:[Int] = [1,1]
        if rowIndex <= 0 { return [1] }
        for _ in 1..<rowIndex{
            var temp:[Int] = [1,1]
            for j in 0..<ans.count{
                if j+1<ans.count{
                    temp.insert(ans[j] + ans[j+1], at: 1)
                }
            }
            ans = temp
        }
        return ans
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.