JasonChang

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

2013年11月8日

摘要: 从后向前遍历 1 public class Solution { 2 public void merge(int A[], int m, int B[], 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 indexA = m - 1; 6 int indexB = n - 1; 7 ... 阅读全文
posted @ 2013-11-08 16:20 JasonChang 阅读(163) 评论(0) 推荐(0) 编辑

摘要: 用双index从头尾两方向同时遍历 1 public class Solution { 2 public void sortColors(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 int frontRunner = 0; 6 int backRunner = A.length - 1;... 阅读全文
posted @ 2013-11-08 15:26 JasonChang 阅读(142) 评论(0) 推荐(0) 编辑

摘要: recursion programming 1 public class Solution { 2 public TreeNode buildTree(int[] preorder, int[] inorder) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(preorder == null) 6 ... 阅读全文
posted @ 2013-11-08 14:51 JasonChang 阅读(148) 评论(0) 推荐(0) 编辑

摘要: recursion programming 1 public class Solution { 2 public ArrayList postorderTraversal(TreeNode root) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 ArrayList result = new ArrayList(); 6 ... 阅读全文
posted @ 2013-11-08 14:05 JasonChang 阅读(179) 评论(0) 推荐(0) 编辑

摘要: recursion programming 1 public class Solution { 2 public boolean isSymmetric(TreeNode root) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(root == null) 6 return true; 7 ... 阅读全文
posted @ 2013-11-08 13:59 JasonChang 阅读(149) 评论(0) 推荐(0) 编辑

摘要: 先按照对角线翻转,再按照x轴翻转 1 public class Solution { 2 public void rotate(int[][] matrix) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int len = matrix.length; 6 if(len == 0) 7 ... 阅读全文
posted @ 2013-11-08 13:51 JasonChang 阅读(142) 评论(0) 推荐(0) 编辑

摘要: 注意边界 1 public class Solution { 2 public int[][] generateMatrix(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 = end)14 return;15 if(end - start == 1){16 ... 阅读全文
posted @ 2013-11-08 13:34 JasonChang 阅读(143) 评论(0) 推荐(0) 编辑

摘要: 1 public class Solution { 2 public boolean isPalindrome(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 || s.length() < 2) 6 return true; 7 Str... 阅读全文
posted @ 2013-11-08 12:41 JasonChang 阅读(133) 评论(0) 推荐(0) 编辑

2013年11月7日

摘要: profit 可以累积 1 public class Solution { 2 public int maxProfit(int[] prices) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(prices == null) 6 return 0; 7 int result ... 阅读全文
posted @ 2013-11-07 13:05 JasonChang 阅读(159) 评论(0) 推荐(0) 编辑

摘要: bfs 1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int x) { val = x; } 8 * } 9 */10 public class Solution {11 public ArrayList> levelOrder(TreeNode root) {12 // IMPORTANT: Please re... 阅读全文
posted @ 2013-11-07 12:58 JasonChang 阅读(152) 评论(0) 推荐(0) 编辑