JasonChang

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

2013年11月12日

摘要: dynamic programming 1 public class Solution { 2 public int numDecodings(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 int length = s.length(); 6 if(0 == length || s.ch... 阅读全文
posted @ 2013-11-12 15:35 JasonChang 阅读(150) 评论(0) 推荐(0) 编辑

摘要: 1 public class Solution { 2 public ArrayList> subsetsWithDup(int[] num) { 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 ArrayList list = n... 阅读全文
posted @ 2013-11-12 13:58 JasonChang 阅读(142) 评论(0) 推荐(0) 编辑

摘要: 1 public class Solution { 2 public ArrayList> subsets(int[] S) { 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 ArrayList list = new ArrayL... 阅读全文
posted @ 2013-11-12 13:57 JasonChang 阅读(200) 评论(0) 推荐(0) 编辑

摘要: 1 public class Solution { 2 public ListNode reverseBetween(ListNode head, 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 ListNode newhead = new ListNode(0); 6 7 ... 阅读全文
posted @ 2013-11-12 13:18 JasonChang 阅读(149) 评论(0) 推荐(0) 编辑

摘要: 1 public class Solution { 2 public ArrayList inorderTraversal(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 traversal(root,... 阅读全文
posted @ 2013-11-12 12:00 JasonChang 阅读(127) 评论(0) 推荐(0) 编辑

摘要: 1 public class Solution { 2 public ArrayList generateTrees(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 return generate(1, n); 6 } 7 public ArrayList generate(int start... 阅读全文
posted @ 2013-11-12 11:49 JasonChang 阅读(157) 评论(0) 推荐(0) 编辑

摘要: 1 public class Solution { 2 public boolean isValidBST(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 if(root.left !=... 阅读全文
posted @ 2013-11-12 06:54 JasonChang 阅读(174) 评论(0) 推荐(0) 编辑

摘要: BFS 1 public class Solution { 2 public ArrayList> zigzagLevelOrder(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 LinkedList visiting = new LinkedList(); 6 LinkedL... 阅读全文
posted @ 2013-11-12 06:13 JasonChang 阅读(164) 评论(0) 推荐(0) 编辑