classSolution {publicintminimumTotal(List<List<Integer>> triangle) {Integer[][] memo =newInteger[triangle.size()][triangle.size()]; // use Integer object!returndivideAndConquer(triangle,0,0, memo); }privateintdivideAndConquer(List<List<Integer>> triangle,int x,int y,Integer[][] memo) {if (x ==triangle.size()) { // reach last rowreturn0; // return no further ans }if (memo[x][y] !=null) {return memo[x][y]; // if has cache, directly return it. }// do divide and conquer in two kinds of movementint move1 =divideAndConquer(triangle, x+1, y, memo); // next row, index yint move2 =divideAndConquer(triangle, x+1, y+1, memo); // next row, index y+1 memo[x][y] =Math.min(move1, move2) +triangle.get(x).get(y); // do cachereturn memo[x][y]; }}// row index: i// next row, index i or i+1/*[2],[3,4],[6,5,7],[4,1,8,3]*/