JasonChang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2013年11月6日

摘要: simple recursion problem 1 public class Solution { 2 public int climbStairs(int n) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int[] table = new int[n+1]; 6 for(int i = 0; i <... 阅读全文
posted @ 2013-11-06 02:03 JasonChang 阅读(146) 评论(0) 推荐(0) 编辑

2013年11月5日

摘要: use stack 1 public class Solution { 2 public String addBinary(String a, String b) { 3 if(a == null||b == null) 4 return ""; 5 if(a.length() == 0) 6 return b; 7 if(b.length() == 0) 8 return a; 9 Stack stack = new Stack();10 ... 阅读全文
posted @ 2013-11-05 17:09 JasonChang 阅读(141) 评论(0) 推荐(0) 编辑

摘要: use stack 1 public class Solution { 2 public int[] plusOne(int[] digits) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(digits == null) 6 return null; 7 Stack myst... 阅读全文
posted @ 2013-11-05 16:56 JasonChang 阅读(187) 评论(0) 推荐(0) 编辑

摘要: recursion programming 1 public class Solution { 2 public int uniquePaths(int m, int n) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int[][] result = new int[m+1][n+1]; 6 result... 阅读全文
posted @ 2013-11-05 16:24 JasonChang 阅读(163) 评论(0) 推荐(0) 编辑

摘要: 1 public class Solution { 2 public int lengthOfLastWord(String s) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(s == null) 6 return 0; 7 char[] mychar = s.trim()... 阅读全文
posted @ 2013-11-05 16:23 JasonChang 阅读(174) 评论(0) 推荐(0) 编辑

摘要: recursion programming 1 public class Solution { 2 public String countAndSay(int n) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(n == 1) 6 return "1"; 7 char[] my... 阅读全文
posted @ 2013-11-05 16:13 JasonChang 阅读(210) 评论(0) 推荐(0) 编辑

摘要: use three 2-d matrix to store if any column, row or block has more than one specific value. 1 public class Solution { 2 public boolean isValidSudoku(char[][] board) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for ... 阅读全文
posted @ 2013-11-05 16:02 JasonChang 阅读(158) 评论(0) 推荐(0) 编辑

摘要: simple recursion programming problemelse if(target < A[mid]) return binarySearch(A, start, mid, target); else return binarySearch(A, mid+1, end, target); 1 public class Solution { 2 public int searchInsert(int[] A, int target) { 3 // IMPORTANT: Please res... 阅读全文
posted @ 2013-11-05 15:47 JasonChang 阅读(222) 评论(0) 推荐(0) 编辑

摘要: same asRemove Duplicates from Sorted Array 1 public class Solution { 2 public int removeElement(int[] A, int elem) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(A == null||A.length <... 阅读全文
posted @ 2013-11-05 15:35 JasonChang 阅读(167) 评论(0) 推荐(0) 编辑

摘要: use two index to compress array 1 public class Solution { 2 public int removeDuplicates(int[] A) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(A == null||A.length < 1) 6 ... 阅读全文
posted @ 2013-11-05 15:19 JasonChang 阅读(204) 评论(0) 推荐(0) 编辑