Learning java-- FIve days, beginner's solution


  • 0
    W
    public class Solution {
    public List<List<Integer>> generate(int numRows) {
        
    	//List<List<Integer>> result = ArrayList<List<Integer>>();
    	List<Integer> pre = new ArrayList<Integer>();
    	List<List<Integer>> result = new ArrayList<List<Integer>>();
    	if (numRows==0){
    		return result;
    	}
    	pre.add(1);
    	for(int i=1;i<=numRows;i++){
    		result.add(pre);
    	    List<Integer> curr = new ArrayList<Integer>();
    	    
    		for(int j=0;j<i+1;j++){
    			if (j==0){
    				curr.add(1);
    			}
    			else if(j!=i && j!=0){
    			curr.add(pre.get(j) + pre.get(j-1));}
    			else{
    				curr.add(1);				
    			}
    			
    		}
    		//Arrays.asList(curr);
    		pre = curr;
    		
    	}
    	
    	return result;
    	
    	
    	
    }
    

    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.