给出一个索引k,返回杨辉三角的第k行 例如,k=3, 返回[1,3,3,1]. 备注: 你能将你的算法优化到只使用O(k)的额外空间吗?
示例1
输入
3
输出
[1,3,3,1]
加载中...
import java.util.*; public class Solution { /** * * @param rowIndex int整型 * @return int整型ArrayList */ public ArrayList
getRow (int rowIndex) { // write code here } }
class Solution { public: /** * * @param rowIndex int整型 * @return int整型vector */ vector
getRow(int rowIndex) { // write code here } };
# # # @param rowIndex int整型 # @return int整型一维数组 # class Solution: def getRow(self , rowIndex ): # write code here
/** * * @param rowIndex int整型 * @return int整型一维数组 */ function getRow( rowIndex ) { // write code here } module.exports = { getRow : getRow };
# # # @param rowIndex int整型 # @return int整型一维数组 # class Solution: def getRow(self , rowIndex ): # write code here
package main /** * * @param rowIndex int整型 * @return int整型一维数组 */ func getRow( rowIndex int ) []int { // write code here }
3
[1,3,3,1]