![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
刷题目
SherryWay
这个作者很懒,什么都没留下…
展开
-
【leetcode】Max Consecutive Ones
这个非常的简单,主要需要考虑的问题是:如果最长连续1是在数组的尾部的话,那么最后flag值没有赋给sum的话会导致返回值错误。public class Solution { public int findMaxConsecutiveOnes(int[] nums) { int sum=0; int flag=0; for(int i=0;i<nu原创 2017-02-22 06:42:22 · 239 阅读 · 0 评论 -
【leetcode】Construct the Rectangle
主要是对Math.sqrt()方法的使用。public class Solution { public int[] constructRectangle(int area) { int weight,length; length=(int) Math.sqrt(area); weight=(int) Math.sqrt(area); while(length*原创 2017-02-22 07:01:25 · 241 阅读 · 0 评论 -
【leetcode】Next Greater Element I
这个马住,以后再找更好的解决办法。这个就是强行解决问题。public class Solution { public static int[] nextGreaterElement(int[] findNums, int[] nums) { int []compare = new int[findNums.length]; for(int i=0;i<find原创 2017-02-22 07:36:42 · 287 阅读 · 0 评论 -
【leetcode】Reverse Integer
需要考虑的问题是一个int型数据在翻转后可能出现的越界问题。而这个问题无法通过最开始对数据的约束来完成的。比如说32bit的数据,最大值为2147483647,那么1463847412是可以翻转的数字,但是1253847412确实不可以反转的数字。public class Solution { public int reverse(int x) {原创 2017-02-14 02:42:56 · 251 阅读 · 0 评论 -
【leetcode】Palindrome Number
这一题非常的容易,主要容易出错的位置是:对base 的值进行更新的时候,需要减少两位数。因为之前删除了原数据一头一尾的内容。另外,不要再代码中使用while(x>0 &&left==right)这样对于10这样的数字判断会出问题。public class Solution { public boolean isPalindrome(int x) { int left=0;原创 2017-02-14 02:39:08 · 171 阅读 · 0 评论 -
【leetcode】13. Roman to Integer
题目的描述如下:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.首先,罗马数字的表示方式如下:M:1000D:500C:100L:50X:10V:5I:1原创 2017-07-23 17:20:00 · 156 阅读 · 0 评论