摘要: java当中的基本数据类型在函数中传递是值传递。 而对象的传递方式是引用,所以这里可以把boolean包裹在一个对象当中,来作为一个全局的引用使用 阅读全文
posted @ 2016-07-12 19:02 阿怪123 阅读(153) 评论(0) 推荐(0)
摘要: public class Solution { public int[] plusOne(int[] digits) { int size=digits.length; int isOverload=0; for(int i=size-1;i>=0;i--) { if(digits[i]==9) ... 阅读全文
posted @ 2016-07-12 17:41 阿怪123 阅读(154) 评论(0) 推荐(0)
摘要: public class Solution { public int addDigits(int num) { int temp=num; while(temp/10!=0) { int res=temp%10; while(temp/10!=0) { ... 阅读全文
posted @ 2016-07-12 17:33 阿怪123 阅读(114) 评论(0) 推荐(0)
摘要: public class Solution { public int missingNumber(int[] nums) { int size=nums.length; int res[]=new int[size+1]; for(int i=0;i<=size;i++) { ... 阅读全文
posted @ 2016-07-12 17:25 阿怪123 阅读(106) 评论(0) 推荐(0)
摘要: public class Solution { public int hIndex(int[] citations) { int answer=0; int size=citations.length; for(int i=0;itemp?answer:temp; } return answer; ... 阅读全文
posted @ 2016-07-12 17:21 阿怪123 阅读(145) 评论(0) 推荐(0)
摘要: public class Solution { public int hIndex(int[] citations) { int size=citations.length; int answer=0; int[] res=new int[size+1]; //对于res数组进行初始化 f... 阅读全文
posted @ 2016-07-12 17:08 阿怪123 阅读(155) 评论(0) 推荐(0)
摘要: 注意大数溢出的问题 阅读全文
posted @ 2016-07-12 16:46 阿怪123 阅读(156) 评论(0) 推荐(0)
摘要: public class Solution { public boolean isUgly(int num) { if(num==0) return false; if(num==1) return true; else { int t... 阅读全文
posted @ 2016-07-12 11:43 阿怪123 阅读(177) 评论(0) 推荐(0)
摘要: import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.LinkedList; import java.util.Queue; /** * Definition for a binary tree node. * public class TreeNode... 阅读全文
posted @ 2016-07-10 12:17 阿怪123 阅读(114) 评论(0) 推荐(0)
摘要: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { ... 阅读全文
posted @ 2016-07-08 22:09 阿怪123 阅读(116) 评论(0) 推荐(0)
摘要: import java.util.ArrayList; import java.util.List; /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(i... 阅读全文
posted @ 2016-07-07 21:59 阿怪123 阅读(88) 评论(0) 推荐(0)
摘要: import java.util.Arrays; public class Solution { public boolean isAnagram(String s, String t) { char []arrayS=s.toCharArray(); char []arrayT=t.toCharArray(); ... 阅读全文
posted @ 2016-07-07 15:18 阿怪123 阅读(91) 评论(0) 推荐(0)
摘要: import java.util.*; public class Solution { public List> combinationSum(int[] candidates, int target) { int size=candidates.length; List> res=new ArrayList>(); ... 阅读全文
posted @ 2016-07-07 14:34 阿怪123 阅读(123) 评论(0) 推荐(0)
摘要: public class Solution { public int getRes(long a,long b) { if(a==0) return 0; if(a=var) { remain-=var; res+=times; var*... 阅读全文
posted @ 2016-05-18 16:41 阿怪123 阅读(187) 评论(0) 推荐(0)
摘要: public class Solution { public static List generateParenthesis(int n) { List res=new ArrayList(); func(0,0,"",res,n); return res; } public static void fun... 阅读全文
posted @ 2016-04-26 10:10 阿怪123 阅读(117) 评论(0) 推荐(0)
摘要: public class Solution { public int[] productExceptSelf(int[] nums) { int size=nums.length; int[] res=new int[size]; //先找到有多少个0位 int num_of_zero=0; int sum_... 阅读全文
posted @ 2016-04-20 09:50 阿怪123 阅读(76) 评论(0) 推荐(0)
摘要: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public void deleteN... 阅读全文
posted @ 2016-04-20 09:25 阿怪123 阅读(102) 评论(0) 推荐(0)
摘要: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { ... 阅读全文
posted @ 2016-04-05 11:16 阿怪123 阅读(78) 评论(0) 推荐(0)
摘要: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { ... 阅读全文
posted @ 2016-04-05 10:41 阿怪123 阅读(94) 评论(0) 推荐(0)
摘要: public class Solution { public int removeElement(int[] nums, int val) { int sum=0; int len=nums.length; int end=len; int i=0; while(i<end) { ... 阅读全文
posted @ 2016-04-04 22:20 阿怪123 阅读(123) 评论(0) 推荐(0)
摘要: public class Solution { public void sortColors(int[] nums) { int len=nums.length; int red=0; int white=0; int blue=0; for(int i=0;i<len;i++) { ... 阅读全文
posted @ 2016-04-04 22:05 阿怪123 阅读(85) 评论(0) 推荐(0)
摘要: public class Solution { public TreeNode sortedArrayToBST(int[] nums) { int len=nums.length; TreeNode res=buildNode(0,len-1,nums); return res; } ... 阅读全文
posted @ 2016-04-04 21:51 阿怪123 阅读(110) 评论(0) 推荐(0)
摘要: public class Solution { public int maxSubArray(int[] nums) { int len=nums.length; if(len==0) return 0; int res=0; int[] results=new int[len]; f... 阅读全文
posted @ 2016-04-04 21:22 阿怪123 阅读(101) 评论(0) 推荐(0)
摘要: public class Solution { public List grayCode(int n) { //格雷码 /* 2位元格雷码 00 01 11 10 3位元格雷码 000 001 011 010 ... 阅读全文
posted @ 2016-04-04 15:06 阿怪123 阅读(147) 评论(0) 推荐(0)
摘要: public class Solution { public boolean searchMatrix(int[][] matrix, int target) { int rows=matrix.length; int columns=matrix[0].length; boolean res=false; for(int ... 阅读全文
posted @ 2016-04-04 14:28 阿怪123 阅读(94) 评论(0) 推荐(0)
摘要: public class Solution { public int findMin(int[] nums) { int len=nums.length; for(int i=0;i=0) { if(nums[i]<nums[i-1]) return nums[... 阅读全文
posted @ 2016-04-04 14:17 阿怪123 阅读(86) 评论(0) 推荐(0)
摘要: 动态规划问题 阅读全文
posted @ 2016-04-04 14:07 阿怪123 阅读(84) 评论(0) 推荐(0)
摘要: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode mer... 阅读全文
posted @ 2016-04-04 13:59 阿怪123 阅读(98) 评论(0) 推荐(0)
摘要: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { ... 阅读全文
posted @ 2016-04-04 13:51 阿怪123 阅读(120) 评论(0) 推荐(0)
摘要: public class Solution { public int climbStairs(int n) { if(n==1) return 1; if(n==2) return 2; int[] res=new int[n+1]; res[1]=1; res... 阅读全文
posted @ 2016-04-04 10:25 阿怪123 阅读(93) 评论(0) 推荐(0)
摘要: /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode del... 阅读全文
posted @ 2016-04-04 10:16 阿怪123 阅读(91) 评论(0) 推荐(0)
摘要: public class Solution { public int searchInsert(int[] nums, int target) { int len=nums.length; int i=0; for(;i=target) break; } return i; ... 阅读全文
posted @ 2016-04-04 10:07 阿怪123 阅读(85) 评论(0) 推荐(0)
摘要: public class Solution { public int numTrees(int n) { //可以采用递归方式,也可以采用线性规划,进行优化 List results=new ArrayList(); for(int i=0;i<=n;i++) { if(i==0||i==1) ... 阅读全文
posted @ 2016-04-03 15:37 阿怪123 阅读(120) 评论(0) 推荐(0)
摘要: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { ... 阅读全文
posted @ 2016-04-03 15:16 阿怪123 阅读(95) 评论(0) 推荐(0)
摘要: /** * Definition for binary tree with next pointer. * public class TreeLinkNode { * int val; * TreeLinkNode left, right, next; * TreeLinkNode(int x) { val = x; } * } */ public clas... 阅读全文
posted @ 2016-04-03 14:41 阿怪123 阅读(113) 评论(0) 推荐(0)
摘要: /** * Definition for binary tree with next pointer. * public class TreeLinkNode { * int val; * TreeLinkNode left, right, next; * TreeLinkNode(int x) { val = x; } * } */ public clas... 阅读全文
posted @ 2016-04-03 14:39 阿怪123 阅读(104) 评论(0) 推荐(0)
摘要: /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { ... 阅读全文
posted @ 2016-04-03 11:44 阿怪123 阅读(113) 评论(0) 推荐(0)
摘要: public class Solution { public int majorityElement(int[] nums) { Map mp=new HashMap(); int len=nums.length; int res=0; if(len==1) return nums[0]; ... 阅读全文
posted @ 2016-04-03 11:37 阿怪123 阅读(136) 评论(0) 推荐(0)
摘要: public class Solution { public int titleToNumber(String s) { int len=s.length(); int res=0; for(int i=0;i<len;i++) { res=res*26; res+=((s.c... 阅读全文
posted @ 2016-04-03 11:30 阿怪123 阅读(137) 评论(0) 推荐(0)
摘要: public class Solution { // you need treat n as an unsigned value public int reverseBits(int n) { int res=0; for(int i=0;i>>((i-15)*2-1)|res); } return res; ... 阅读全文
posted @ 2016-04-03 11:25 阿怪123 阅读(88) 评论(0) 推荐(0)