- 博客(7)
- 收藏
- 关注
原创 【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:1000 D:500 C:100 L:50 X:10 V:5 I:1
2017-07-23 17:20:00 164
原创 【leetcode】142. Linked List Cycle II
第142是第141的一个升级版, Given a linked list, determine if it has a cycle in it. 141要求的是查出是否存在有一个链表的循环; Given a linked list, return the node where the cycle begins. If there is no cycle, return null.
2017-05-29 18:46:05 208
原创 【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 295
原创 【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 250
原创 【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 246
原创 【leetcode】Reverse Integer
需要考虑的问题是一个int型数据在翻转后可能出现的越界问题。 而这个问题无法通过最开始对数据的约束来完成的。 比如说32bit的数据,最大值为2147483647,那么1463847412是可以翻转的数字,但是1253847412确实不可以反转的数字。 public class Solution { public int reverse(int x) {
2017-02-14 02:42:56 262
原创 【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 180
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人