- 博客(17)
- 收藏
- 关注
原创 Minimum Depth of Binary Tree
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { publi...
2014-05-20 11:39:58 534
原创 Longest Common Prefix
public class Solution { public String longestCommonPrefix(String[] strs) { int len = strs.length; if(len == 0){ return ""; } if(len == 1){ return strs[0]; } int length =...
2014-05-20 10:20:19 483
原创 Sum Root to Leaf Numbers
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { publi...
2014-05-20 09:42:06 544
原创 Binary Tree Level Order Traversal
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { publi...
2014-05-15 20:20:07 515
原创 Longest Consecutive Sequence
public class Solution { public int longestConsecutive(int[] num) { Arrays.sort(num); int count = 1; int res = 1; int tmp = 0 ; int countTmp = 0; for(int i = 1 ; i < num.len...
2014-05-15 20:10:46 493
原创 Plus One
public class Solution { public int[] plusOne(int[] A) { if(A.length >= 1) { int[] B = new int[A.length + 1]; int added = 1; for(int i = A.length - 1 ; i >= 0 ; i--){ i...
2014-05-14 19:31:29 498
原创 Single Number II
public class Solution { public int singleNumber(int[] A) { Arrays.sort(A); // for(int i = 0 ; i < A.length ; i++){ // System.out.println(A[i]); // } int...
2014-05-14 13:59:39 524
原创 Remove Duplicates from Sorted Array II
public class Solution { public int removeDuplicates(int[] A) { int count = 0; int tmp = 0; if(A == null || A.length == 0){ return 0; } if(A.leng...
2014-05-12 16:56:30 473
原创 Remove Duplicates from Sorted List
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */ public...
2014-05-12 15:16:20 667
原创 Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Arraypublic class Solution { public int removeDuplicates(int[] A) { boolean isEqual = false; int count = 0; int tmp = 0; if(A == null...
2014-05-12 09:03:53 491
原创 Convert Sorted Array to Binary Search Tree
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { publi
2014-05-06 18:59:05 452
原创 Binary Tree Level Order Traversal II
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { publi...
2014-05-06 18:57:09 710
原创 Length of Last Word
public class Solution { public int lengthOfLastWord(String s) { int res = 0; if(s.length() == 0){ return res; } char[] sArray = s.toCharArray(); ...
2014-05-06 09:02:53 443
原创 Balanced Binary Tree
public class Solution { public boolean isBalanced(TreeNode root) { if(root == null){ return true; } int depth = maxDepth(root.left) - maxDepth(root.right);
2014-05-05 20:03:21 608
原创 Maximum Subarray
public class Solution { public int maxSubArray(int[] A) { int res = 0; if(A.length == 0){ return res; } int max = A[0]; for(int i = 0 ; i < A.le
2014-05-04 17:24:38 408
原创 Pow(x, n)
public class Solution { public double pow(double x, int n) { double res = 1; if(n == 0){ return res; }else if(n > 0){ if(n == 1){ re
2014-05-04 16:12:31 491
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人