118. Pascal's Triangle
Given the root of a binary tree and an integer targetSum, returns true if the tree has a path from root to leaf such that the addition of all values along the path equals targetSum.
A leaf is a node that has no children.
Example 1:
Input: root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22
Output: true
Description : Shows the path from the root to the leaf containing the goal sum.
Example 2:
Input: root = [1,2,3], targetSum = 5
Output: false
Description: The tree has two root-to-leaf paths:
(1 --> 2 ) : the sum is 3.
(1 --> 3): Total is 4.
There is no path from root to leaf with sum = 5.
Example 3:
Input: root = [], targetSum = 0
Output: false
Description: There is no root because the tree is empty - the path to the sheet.
Limits:
The number of nodes in the tree is in the range [0, 5000].
-1000 <= Node.val <= 1000
-1000 <= targetSum <= 1000
Given an integer numRows , returns the first numRows of Pascal's triangle.
In Pascal's triangle, each number is the sum of the two numbers immediately above it: [ 1, 2,1],[1,3,3,1],[1,4,6,4,1]]
Example 2:
Input: numRows = 1
Output: [[1]]
Limit:
1 <= numRows <= 30
Solution
class Solution {
public:
int a=1000000007;
vector> generate(int n)
{
vector> ans;
vector v;
v.push_back(1);
ans.push_back(v);
int s=2;
n--;
while(n--)
{
vector t(s);
t[0]=v[0];
t[s-1]=v[v.size()-1];
if(t.size()>2)
{
for(int i=1;i
Comments
Post a Comment