기록하는 공간

[leetcode/kotlin] 118. Pascal's Triangle 본문

알고리즘/leetcode

[leetcode/kotlin] 118. Pascal's Triangle

llollhh_ 2020. 8. 24. 22:40
class Solution {
    fun generate(numRows: Int): List<List<Int>> {
        
        val totalArr: MutableList<List<Int>> = mutableListOf()
        var innerArr: MutableList<Int> = mutableListOf(1)
        for (i in 0 until numRows) {
            totalArr.add(innerArr)
            val _innerArr: MutableList<Int> = mutableListOf()
            _innerArr.add(1)
            for (j in 0 until innerArr.size - 1) {
               _innerArr.add(innerArr[j] + innerArr[j +1 ]) 
            }
            _innerArr.add(1)
            
            innerArr = _innerArr
        }
        
        return totalArr
    }
}
Comments