自己刷leetcode的第二天1
来源:互联网 发布:八爪网络科技 知乎 编辑:程序博客网 时间:2024/04/27 20:34
1.reverse integer的问题
今天用了一个十分简单的题目入手作为开胃菜。不想依然犯了很严重的错误,真真是不应该啊
很简单的一个问题,由于自己的粗心,没有考虑周全。
关于溢出的问题,对数字的操作需要特别考虑这个问题,加减乘除以后都可能产生溢出,对于溢出,我们要用try和catch来解决
其次,对于翻转一个integer like 100 反转后的结果应该是1而不是001。
2.container with most water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
解释:
因为一个container能装的水的多少实际上是取决于短板
要使一个container装的水变多,那么肯定需要在短板上进行处理,此题当中,当然就是要移动短板
如果短板移动过后,能装的水变多了,那么更新容量,如果没有变多活着变少了,那么便不移动短板,就是这么简单
只要两个短板不相遇或者不交叉,那么就可以移动
public int maxArea(int[] height) {int left=0;int right=height.length-1;int maxVolumn=min(height[left],height[right])*(right-left);while(left<right){if(height[left]<height[right]){left++;int m=height[left]>height[right]?height[right]*(right-left):height[left]*(right-left);maxVolumn=maxVolumn>m?maxVolumn:m;}else{right--;int m=height[left]>height[right]?height[right]*(right-left):height[left]*(right-left);maxVolumn=maxVolumn>m?maxVolumn:m;}}return maxVolumn; }public static int min(int a,int b){return a>b?b:a;}
0 0
- 自己刷leetcode的第二天1
- 我自己改变的第二天
- LeetCode第二天
- LeetCode第二天
- 实现自己的操作系统 第二部分
- 第二章,开启自己的心智
- 自己刷Leetcode的笔记:Longest Palindromic Substring
- 实习第二天(觉得自己很烂)
- 黑马程序员就业班第二天的总结以及自己的看法
- leetcode第二遍不需要做的题目
- leetcode 第二题:链表的使用
- 第二章 构架属于自己的WMTS服务,数据下载整合篇1
- 上班(实习)第二天了,感觉自己很荣幸能加入这个公司,勉励自己一定要为这个公司做出自己的贡献
- 每天一题LeetCode [第二天]
- 《卓有成效的管理者》笔记,第二章 掌握自己的时间
- 备份LeetCode OJ自己编写的代码
- LeetCode 520. Detect Capital 自己的解法
- LeetCode 383. Ransom Note 自己的解法
- 诱导公式
- android L WLAN管理
- jpa双向多对多关联关系
- 技术博客第一天
- 测试sql语句的执行时间
- 自己刷leetcode的第二天1
- Android中Bitmap,byte[],Drawable相互转化
- 做装砖祝诅嘴遵孜谞姿着住邹篆资钻紫赚
- (document)与$(window)的几个常用属性辨析
- 淄专滓罪琢资踪椎最滓昨抓纵子卒专专谞
- eclipse开发C++环境搭建
- 正则表达式语法
- [学习笔记]JavaScript基础
- 茁爪祝兹做妆卓走醉走桌缀淄邹最子资揍