Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.
Note that the row index starts from 0.
給予一個非負數索引值k,且k ≤ 33,回傳帕斯卡三角形中的第k列。
注意,索引從零開始。
Learn More →
Input: 3
Output: [1,3,3,1]
118
題的code,改成只輸出最後一列即可。
class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> ans;
for(int i=0;i<=rowIndex;i++)
{
vector<int> temp;
for(int j=0;j<=i;j++)
{
if(j==i || j==0)
{
temp.push_back(1);
}
else
{
temp.push_back(ans[j-1]+ans[j]);
}
}
ans=temp;
}
return ans;
}
};
LeetCode
C++
1. Two Sum
Nov 15, 2023You are given an array of positive integers arr. Perform some operations (possibly none) on arr so that it satisfies these conditions:
Nov 15, 2023Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 109 + 7.
Nov 9, 2023There are n computers numbered from 0 to n - 1 connected by ethernet cables connections forming a network where connections[i] = [ai, bi] represents a connection between computers ai and bi. Any computer can reach any other computer directly or indirectly through the network.
Nov 9, 2023or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up