求小米蓄水池。。。

RT。。。有没有大佬AC的#小米#
全部评论
这个题是说可以给多面墙增高(可以减吗)?还是只能给一面墙?
点赞 回复 分享
发布于 2018-09-22 23:06
看二楼的代码,难道是 LeetCode 42 接雨水
点赞 回复 分享
发布于 2018-09-20 21:13
// 2.蓄水池总量 var arr = [0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1] function count(arr) { var start = 0, end = 1, sum = 0, len, max, S = 0,temp while (end < arr.length) { while (arr[start] <= arr[start + 1]) start++ console.log('start:', start) end = start + 1 while (arr[end] <= arr[start]) end++ console.log('end:',end) if(end===arr.length){ var endIndex = end while(arr[endIndex-2]>arr[endIndex-1]) endIndex-- temp = arr.slice(start, endIndex) }else{ temp = arr.slice(start, end + 1) } console.log('蓄水区域:',temp) temp = temp.sort() len = temp.length max = temp[len - 2] for (var i = 0; i < len; i++) { if (temp[i] !== 0) if(temp[i] <= max) S += temp[i] else S+= max } // 两端比较矮一处为高,数组长度为宽,盛水量=总面积-方块占用面积 sum += ((len * max) - S) console.log(sum,len,max,S) start = end S = 0 end = start + 1 } console.log(sum) } count(arr)
点赞 回复 分享
发布于 2018-09-20 21:10
能发一下题目截图吗
点赞 回复 分享
发布于 2018-09-20 21:06

相关推荐

04-14 20:10
已编辑
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
4
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务