Paint House
2016-06-16 02:46
351 查看
想想想
public class Solution {
public int minCost(int[][] costs) {
if (costs == null || costs.length == 0) {
return 0;
}
for (int i = 1; i < costs.length; i++) {
costs[i][0] = costs[i][0] + Math.min(costs[i - 1][1], costs[i - 1][2]);
costs[i][1] = costs[i][1] + Math.min(costs[i - 1][0], costs[i - 1][2]);
costs[i][2] = costs[i][2] + Math.min(costs[i - 1][0], costs[i - 1][1]);
}
return Math.min(costs[costs.length - 1][0], Math.min(costs[costs.length - 1][1], costs[costs.length - 1][2]));
}
}
public class Solution {
public int minCost(int[][] costs) {
if (costs == null || costs.length == 0) {
return 0;
}
for (int i = 1; i < costs.length; i++) {
costs[i][0] = costs[i][0] + Math.min(costs[i - 1][1], costs[i - 1][2]);
costs[i][1] = costs[i][1] + Math.min(costs[i - 1][0], costs[i - 1][2]);
costs[i][2] = costs[i][2] + Math.min(costs[i - 1][0], costs[i - 1][1]);
}
return Math.min(costs[costs.length - 1][0], Math.min(costs[costs.length - 1][1], costs[costs.length - 1][2]));
}
}
相关文章推荐
- Openstack组件部署 — keystone(domain, projects, users, and roles)
- 2D Closest Pair Problem
- 朴素贝叶斯简易解释
- Intellij Idea essentails 翻译
- xiugai DNS
- 将main方法打成jar包,并引用第三方的maven jar包
- failed to load the JNI shared library
- Conversion to Dalvik format failed: Unable to execute dex: method ID not in [0, 0xffff]: 65536
- FATAL EXCEPTION: main,创建两个Activity,运行子Activity时程序崩溃的可能解决办法
- 等待通知机制 wait,notify,notifyAll
- git当移动文件与更改文件共存Please enter a commit message to explain why this merge is necessary
- The XLIFF file does not contain a target language
- AIDL跨进程通讯访问远程服务
- 李开复万字长文科普人工智能:AI是什么 将带我们去哪儿?
- Storyboard 上 ContainerView
- leetcode No11. Container With Most Water
- Xcode xxxx.a(Native_Sensors_Plugin.o)' does not contain bitcode
- 解密airsync协议
- AirBus手册DTD分析
- 出现( linker command failed with exit code 1)错误总结