Is it good solution? Please, check it and give me some response.


  • 0
    O
    public class Solution {
        public List<Integer> getRow(int rowIndex) {
        	List<Integer> result = new ArrayList<Integer>();
        	List<Integer> list;
    
        	for(int i = 0; i <= rowIndex; i++) {
        		list = new ArrayList<Integer>(result);
        		result.clear();
        		result.add(1);
        		for(int j = 1; j < list.size(); j++) {
        			result.add(list.get(j-1) + list.get(j));
        		}
        		if (i != 0) {
        			result.add(1);
        		}
        	}
        	
            return result;
        }
    }

Log in to reply
 

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