摘要: 代码:public class Solution { public void moveZeroes(int[] nums) { int i = 0, j = 0; while(ji) nums[i] = nums[j]; i++; ... 阅读全文
posted @ 2016-01-13 14:46 爱推理的骑士 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 注意整型数溢出的情况 用recursion做:代码:/* The isBadVersion API is defined in the parent class VersionControl. boolean isBadVersion(int version); */public clas... 阅读全文
posted @ 2016-01-13 13:50 爱推理的骑士 阅读(135) 评论(0) 推荐(0) 编辑
摘要: 代码:public class Solution { public boolean isUgly(int num) { if(num == 0) return false; //if(num == 1 || num == 2 || num == 3 || num =... 阅读全文
posted @ 2016-01-13 12:37 爱推理的骑士 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 数学规律:https://en.wikipedia.org/wiki/Digital_root代码:public class Solution { public int addDigits(int num) { return 1+(num-1)%9; }} 阅读全文
posted @ 2016-01-13 12:13 爱推理的骑士 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 代码:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) ... 阅读全文
posted @ 2016-01-13 12:01 爱推理的骑士 阅读(108) 评论(0) 推荐(0) 编辑
摘要: 创建两个数组存储字母的个数,再对比两个数组是否相同代码:public class Solution { public boolean isAnagram(String s, String t) { int[] alphabets1 = new int[26]; in... 阅读全文
posted @ 2016-01-13 10:35 爱推理的骑士 阅读(121) 评论(0) 推荐(0) 编辑
摘要: 代码:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */pub... 阅读全文
posted @ 2016-01-13 07:40 爱推理的骑士 阅读(112) 评论(0) 推荐(0) 编辑
摘要: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { v... 阅读全文
posted @ 2016-01-13 06:44 爱推理的骑士 阅读(101) 评论(0) 推荐(0) 编辑
摘要: 代码:class MyQueue { // Push element x to the back of queue. Stack stack = new Stack(); Stack aux = new Stack(); public void push(int x) { ... 阅读全文
posted @ 2016-01-13 05:31 爱推理的骑士 阅读(111) 评论(0) 推荐(0) 编辑
摘要: Two's complement of integer:https://zh.wikipedia.org/wiki/%E4%BA%8C%E8%A3%9C%E6%95%B8Bit Manipulation:https://docs.oracle.com/javase/tutorial/java/nut... 阅读全文
posted @ 2016-01-13 05:17 爱推理的骑士 阅读(162) 评论(0) 推荐(0) 编辑
摘要: Functions of StringBuilder:代码:public class Solution { public List summaryRanges(int[] nums) { List list = new ArrayList(); if(nums.le... 阅读全文
posted @ 2016-01-13 04:45 爱推理的骑士 阅读(138) 评论(0) 推荐(0) 编辑