摘要: public class Solution { public int removeDuplicates(int[] A) { if(A.length == 0) return 0; int count = 1; for(int i = 1; i < A.length; i++){ if(A[i-1] == A[i]) continue; A[count++] = A[i]; ... 阅读全文
posted @ 2014-02-06 13:29 Razer.Lu 阅读(145) 评论(0) 推荐(0) 编辑
摘要: Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */pub... 阅读全文
posted @ 2014-02-06 03:50 Razer.Lu 阅读(158) 评论(0) 推荐(0) 编辑
摘要: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array[−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray[4,−1,2,1]has the largest sum =6.click to show more practice.More practice:If you have figured out the O(n) solution, try 阅读全文
posted @ 2014-02-06 03:40 Razer.Lu 阅读(522) 评论(0) 推荐(0) 编辑
摘要: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number inCmay only be usedoncein the combination.Note:All numbers (including target) will be positive integers.Elements in a combination (a1,a2, … ,ak) must 阅读全文
posted @ 2014-02-06 03:00 Razer.Lu 阅读(162) 评论(0) 推荐(0) 编辑
摘要: Given a set of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Thesamerepeated number may be chosen fromCunlimited number of times.Note:All numbers (including target) will be positive integers.Elements in a combination (a1,a2, … ,ak 阅读全文
posted @ 2014-02-06 02:57 Razer.Lu 阅读(153) 评论(0) 推荐(0) 编辑
摘要: Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character'.'.You may assume that there will be only one unique solution.A sudoku puzzle......and its solution numbers marked in red. 1 public class Solution { 2 public void solveSudoku(char[] 阅读全文
posted @ 2014-02-06 02:18 Razer.Lu 阅读(160) 评论(0) 推荐(0) 编辑
摘要: Determine if a Sudoku is valid, according to:Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character'.'.A partially filled sudoku which is valid.rules:1. 同一行中1-9出现次数不重复2. 同一列中1-9出现次数不重复3. 9宫格中1-9出现次数不重复九宫格 block的顺序0 1 23 4 56 7 8 阅读全文
posted @ 2014-02-06 01:30 Razer.Lu 阅读(167) 评论(0) 推荐(0) 编辑