Java 1ms normal solution


  • 0
    H
    public List<Integer>  getRow(int rowIndex) {
           Integer[] arr = new Integer[rowIndex + 1];
    	    arr[0] = 1;
    		// i is column index
    		for (int i = 1; i < rowIndex + 1; i++) {
    			int half = i / 2;
    			boolean moreThenHalf = i % 2 == 0;
    			if (moreThenHalf) {
    				arr[half] = arr[half] + arr[half - 1];
    			}
    			for (int j = moreThenHalf ? half - 1 : half; j > 0; j--) {
    				arr[j] = arr[j] + arr[j - 1];
    				arr[i - j] = arr[j];
    			}
    			if(i==1||i==rowIndex){
    			    arr[i]=1;
    			}
    		}
    		return Arrays.asList(arr);
        }

Log in to reply
 

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