3ms Golang sulotion


  • 0
    M
    • Do you have any other sulotion using golang? If you have please tell me.
    func generate(numRows int) [][]int {
    	var result [][]int = make([][]int, 0, numRows)
    
    	for i := 0; i < numRows; i++ {
    		result = append(result, getRow(i))
    	}
    	return result
    }
    
    func getRow(rowNumber int) []int {
    	var result []int = make([]int, 0, rowNumber+1)
    	result = append(result, 1)
    
    	for i := 1; i <= rowNumber; i++ {
    		for j := len(result) - 2; j >= 0; j-- {
    			result[j+1] = result[j] + result[j+1]
    		}
    		result = append(result, 1)
    	}
    	return result
    }
    

Log in to reply
 

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