问题描述:

Given an index k, return the kth row of the Pascal's triangle.

Note:
Could you optimize your algorithm to use only O(k) extra space?

示例:

For example, given k = 3,
Return [1,3,3,1].

问题来源:Pascal's Triangle II (详细地址:https://leetcode.com/problems/pascals-triangle-ii/description/)

思路分析:相比较Pascal Triangle问题而言,这道题不再输出整个杨辉三角了,而是输出指定的某一行了,所以这里采用第二种方法更容易解了,不容保存那么多数据,只需要最后生成一个list就行了。注意:因为是要输出第k行的,和索引从0开始是一致的,最后i得等于k才能行,千万别知道k-1行就完了。

代码:

Leetcode之Pascal's Triangle II 问题

相关文章:

  • 2022-12-23
  • 2021-12-19
  • 2021-10-08
  • 2022-01-12
  • 2022-12-23
  • 2021-05-01
  • 2021-04-28
  • 2021-04-17
猜你喜欢
  • 2022-12-23
  • 2022-01-27
  • 2022-02-23
  • 2022-02-26
  • 2021-08-12
  • 2021-10-07
相关资源
相似解决方案