摘要: 从后面开始推倒 最后一个是最大数, 当前位置的后一个位置是后面一段的最小数,再分别对和最小数和最大数比较,如果小于最小数直接交换两个位置的值,如果小于最大数,则从末尾开始找最前位置刚刚大于当前值,交换两个位置的值。代码:public class Solution { public void n... 阅读全文
posted @ 2016-01-16 11:53 爱推理的骑士 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 注意 Integer.MIN_VALUE * (-1) 会溢出, 这里所有变量变成long防止溢出除数*2 对映的倍数(商)也会乘以2;再用被除数减去除数*2^n 剩余的数如果依然能被除数整除,接着循环操作代码:public class Solution { public int divide... 阅读全文
posted @ 2016-01-16 10:24 爱推理的骑士 阅读(234) 评论(0) 推荐(0) 编辑
摘要: 注意用指针记录节点的前一个节点位置。代码:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { va... 阅读全文
posted @ 2016-01-16 07:19 爱推理的骑士 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 一开始用hashset 对于怎么从上一个情况准确找出加一个括号后的所有可能性,找不到正确的规律,我想的是hashset.add("("+s+")");hashset.add("()"+s);hashset.add(s+"()");但并没有涵盖所有的情况。就用了DP去做; P(n) = P(n-1-i... 阅读全文
posted @ 2016-01-16 05:24 爱推理的骑士 阅读(128) 评论(0) 推荐(0) 编辑
摘要: 思路 参数里调用上一个list 读取出来 再加上新的letter组成新的string加入到新的list中,最后返回新的list代码:public class Solution { public List letterCombinations(String digits) { Li... 阅读全文
posted @ 2016-01-16 02:58 爱推理的骑士 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 最原始的方法:public class Solution { public int threeSumClosest(int[] nums, int target) { int len = nums.length; if(len target){ ... 阅读全文
posted @ 2016-01-15 11:32 爱推理的骑士 阅读(119) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public String intToRoman(int num) { int[] digits = new int[4]; int i = 0; String s = ""; digits... 阅读全文
posted @ 2016-01-15 08:06 爱推理的骑士 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 代码:public class Solution { public int maxArea(int[] height) { int low = 0; int high = height.length - 1; if(high maxArea) max... 阅读全文
posted @ 2016-01-15 07:07 爱推理的骑士 阅读(119) 评论(0) 推荐(0) 编辑
摘要: No loop; No recursion; 我没找到规律 但是从讨论区看到别人的思路:IfNis a power of3:It follows that3^X == NIt follows thatlog (3^X) == log NIt follows thatX log 3 == log NI... 阅读全文
posted @ 2016-01-15 06:04 爱推理的骑士 阅读(127) 评论(0) 推荐(0) 编辑
摘要: 代码:public class NumArray { private int[] sum; //private int[] nums; public NumArray(int[] nums) { int len = nums.length; sum = ... 阅读全文
posted @ 2016-01-14 15:21 爱推理的骑士 阅读(128) 评论(0) 推荐(0) 编辑