Pascal's Triangle Leetcode Python Java

Given numRows, generate the first numRows of Pascal's triangle.

For example, given numRows = 5,
Return

[
     [1],
    [1,1],
   [1,2,1],
  [1,3,3,1],
 [1,4,6,4,1]
]

Python:

#coding:utf-8
class Solution:
        def resolve(self,target):
                triangle=[]
                if(target<=0){
                        return triangle
                }
                for i in range(target):
                        sub=[]
                        for j in range(0,i+1):
                                if j==0 or j==i:
                                        sub.append(1)
                                else:
                                        sub.append(triangle[i-1][j-1]+triangle[i-1][j])
                        triangle.append(sub)
                return triangle
Java:

java:

public class Solution{
        public List> generate(int numRows){
                List> triangle=new ArrayList>();
                if(numRows<=0){
                        return triangle;
                }
                for(int i=0;i row=new ArrayList();
                        for(int j=0;j


你可能感兴趣的:(java,python,Leetcode)