这也算不错?
来源:互联网 发布:汽车销售行业分析数据 编辑:程序博客网 时间:2024/06/13 21:20
不关套路仅仅是一些好的想法总结。 if (A.length < 3)return 0; int ans = 0; int l = 0, r = A.length -1; while (l < r&& A[l] <= A[l + 1]) l++; while (l < r&& A[r] <= A[r - 1]) r--; while (l < r) { int left = A[l]; int right = A[r]; if (left <= right) { while (l< r && left >= A[++l]) { ans += left - A[l]; } } else { while (l< r && A[--r] <= right) { ans += right - A[r]; } } } return ans;
int sc = 0; int e = 0; int max = 0; for(int i=0; i max =Math.max(max, i+A[i]); if( i == e) { sc++; e = max; } } return sc;
1、将数组对应到坐标系成柱状图看最多能装多少水
a)笨++:从中间往两边计算遇高柱减去外层与内层差,最后头尾指向同一地方时真是自己给自己挖个大坑啊
b)笨:分割成小的凹块,递归计算之,就是代码量加多了吧
c)笨--:从两边往中间遇到不增加高度的高柱开始计算每次计算高度落差一次循环解决
public int trap(int[] A) {
}
2.数组内的最短路劲移动
a)笨++:双重循环暴力全计算之,超时,
b)笨:这不是图最短路劲嘛递归之,超时,
c)笨--:肯定会有每一步增长的边界,找出边界啊!
public int jump(int[] A){
}
所以感觉脑子已经开始对自己不友好了哎!
0 0
- 这也算不错?
- 不错!
- 不错
- 不错
- 不错
- 不错
- 不错
- 不错
- 不错
- 不错!
- 不错
- 不错
- 不错
- 不错!
- 不错
- 不错
- 不错
- 不错
- 杂乱慢述
- Android-程序退出结束所有activity
- 流水
- Backtracking
- Dynamic Programming
- 这也算不错?
- git cherry-pick 出错
- Contest Review
- Eloquent JavaScript 笔记 三: Functions
- eclipse使用技巧
- 26. Remove Duplicates from Sorted Array
- Eclipse中将Java项目转换成Web项目的方法
- css锚伪类
- iOS开发之总结几个提高开发效率的小技巧