上一页 1 ··· 5 6 7 8 9 10 下一页
摘要: 第一种方法TheSieve of Eratosthenesis one of the most efficient ways to find all prime numbers up ton.The Sieve of Eratosthenes uses an extra O(n) memory an... 阅读全文
posted @ 2016-01-10 13:03 爱推理的骑士 阅读(130) 评论(0) 推荐(0) 编辑
摘要: 数据结构:单向链表。指针操作,注意Null Pointer的情况 以及链表头指针的操作代码:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; *... 阅读全文
posted @ 2016-01-10 09:29 爱推理的骑士 阅读(78) 评论(0) 推荐(0) 编辑
摘要: 用hashMap查重:代码:public class Solution { public boolean isHappy(int n) { Map map = new HashMap(); while(!map.containsKey(n)){ ... 阅读全文
posted @ 2016-01-10 09:00 爱推理的骑士 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 用DP思维很好解决 注意终止条件 这里添加了一个数组 length = nums.length + 1;代码:public class Solution { public int rob(int[] nums) { int[] money = new int[nums.lengt... 阅读全文
posted @ 2016-01-10 07:20 爱推理的骑士 阅读(100) 评论(0) 推荐(0) 编辑
摘要: 和 reverse Bits同一类型代码:public class Solution { // you need treat n as an unsigned value public int reverseBits(int n) { int result = 0; ... 阅读全文
posted @ 2016-01-10 04:35 爱推理的骑士 阅读(113) 评论(0) 推荐(0) 编辑
摘要: 复习 二进制位操作(bit operation),32bit integer 取值范围:-2^31 -- 2^31-101111111=12700000010=200000001=100000000=011111111=−111111110=−210000001=−12710000000=−128(... 阅读全文
posted @ 2016-01-10 04:33 爱推理的骑士 阅读(137) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public void rotate(int[] nums, int k) { if(nums.length < 2) return; k = k % nums.length; if(k == 0) re... 阅读全文
posted @ 2016-01-09 07:17 爱推理的骑士 阅读(86) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public int trailingZeroes(int n) { int result = 0; while(n > 0){ n = n/5; result += n; ... 阅读全文
posted @ 2016-01-08 11:35 爱推理的骑士 阅读(125) 评论(0) 推荐(0) 编辑
摘要: 首先 试着 用hashMap来做 习惯一下Mappublic class Solution { public int majorityElement(int[] nums) { Map hashMap = new HashMap(); for(int i = 0; ... 阅读全文
posted @ 2016-01-08 08:14 爱推理的骑士 阅读(124) 评论(0) 推荐(0) 编辑
摘要: public class Solution { public String convertToTitle(int n) { StringBuilder sb = new StringBuilder(); int round = n; while(rou... 阅读全文
posted @ 2016-01-08 07:34 爱推理的骑士 阅读(101) 评论(0) 推荐(0) 编辑
上一页 1 ··· 5 6 7 8 9 10 下一页