mysql 字符串函数(查询处理字符串)
2013-03-27 15:07
519 查看
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
For example,
Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.
对于每一个点来说,蓄水量 = min(左边的最高点,右边的最高点)-本身高度,于是两次遍历,一次用来找每个点的左边的最高点,一次用来找每个点的右边的最高点。
For example,
Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6.
对于每一个点来说,蓄水量 = min(左边的最高点,右边的最高点)-本身高度,于是两次遍历,一次用来找每个点的左边的最高点,一次用来找每个点的右边的最高点。
public class Solution { public int trap(int[] A) { int result = 0; if(A.length<3){ return 0; } int []temp = new int[A.length]; int left = A[0]; for(int i=1;i<A.length-1;i++){ if(A[i]<left){ temp[i] = left; }else if(A[i]>left){ left = A[i]; } } int right = A[A.length-1]; for(int i=A.length-2;i>0;i--){ if(A[i]<right){ if(temp[i]>0){ result += (min(temp[i],right)-A[i]); } }else if(A[i]>right){ right = A[i]; } } return result; } public int min(int a,int b){ return a>b?b:a; } }本文出自 “在云端” 博客,请务必保留此出处http://kcy1860.blog.51cto.com/2488842/1349956
相关文章推荐
- mysql字符串处理-查询两个字符串之间的内容
- 利用mysql 字符串函数 find_in_set()查询包含字符串
- mysql 学习---->字符串、数值处理、日期、查询的逻辑处理、系统相关内容查询、IP地址相关、密码
- mysql 学习记录(五)--字符串、数值处理、日期、查询的逻辑处理、系统相关内容查询、IP地址相关、密码
- 测试mysql查询中参数整形和字符串类型错误索引使用情况
- MySQL中特定格式的字符串部分完全匹配查询
- mysql处理海量数据时的一些优化查询速度方法
- MYSQL中利用select查询某字段中包含以逗号分隔的字符串的记录方法
- MYSQL查询某字段中以逗号分隔的字符串的方法
- mysql把查询的结果集合并成一个字符串
- MYSQL存储过程查询返回结果处理方法
- MySQL查询处理过程分析
- mysql处理海量数据时的一些优化查询速度方法
- MYSQL中利用select查询某字段中包含以逗号分隔的字符串的记录方法find_in_set
- mysql查询字符串替换语句小结(数据库字符串替换)
- mysql 及字符串处理技巧.
- mysql--慢查询,卡死等处理
- MySQL种字符串拆分(substring_index)并作为关联查询条件后多列展示
- 如何优化Mysql千万级快速分页,limit优化快速分页,MySQL处理千万级数据查询的优化方案!