严氏北美IT公司面试真题汇总和解答论坛
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Paint House I lc原题 需bug free

Go down

Paint House I lc原题 需bug free Empty Paint House I lc原题 需bug free

Post by Admin Sat Oct 21, 2017 4:41 pm

public int minCost(int[][] matrix) {
if(matrix==null||matrix.length==0)
return 0;
int m = matrix.length-1;
for(int i=1; i<matrix.length; i++){
matrix[i][0] += Math.min(matrix[i-1][1], matrix[i-1][2]);
matrix[i][1] += Math.min(matrix[i-1][0], matrix[i-1][2]);
matrix[i][2] += Math.min(matrix[i-1][0], matrix[i-1][1]);
}
return Math.min(Math.min(matrix[m][0], matrix[m][1]), matrix[m][2]);
}

Admin
Admin

Posts : 124
Join date : 2017-10-21

https://csinterviewquestions.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum