JasonChang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 18 下一页

2013年11月11日

摘要: dynamic programming 1 public class Solution { 2 public static int minCut(String s) { 3 // Start typing your Java solution below 4 // DO NOT write main() function 5 if (s == null) { 6 return 0; 7 } 8 int len = s.length(); 9 int[] cuts = ... 阅读全文
posted @ 2013-11-11 08:57 JasonChang 阅读(160) 评论(0) 推荐(0) 编辑

摘要: 注意add arraylist 到 ArrayList>的时候传递引用和传值得区别!!! 1 public class Solution { 2 public ArrayList> partition(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 ArrayList> result = new Arra... 阅读全文
posted @ 2013-11-11 08:09 JasonChang 阅读(177) 评论(0) 推荐(0) 编辑

摘要: BFS 用hashmap记录对应关系 1 public class Solution { 2 public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(node == null) 6 ... 阅读全文
posted @ 2013-11-11 07:26 JasonChang 阅读(176) 评论(0) 推荐(0) 编辑

摘要: dynamic programming 1 public class Solution { 2 public boolean wordBreak(String s, Set dict) { 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||dict.isEmpty()) 6 re... 阅读全文
posted @ 2013-11-11 06:53 JasonChang 阅读(210) 评论(0) 推荐(0) 编辑

2013年11月9日

摘要: 只有一个答案,找到最后一个不可以的点,下一个是开始点 1 public class Solution { 2 public int canCompleteCircuit(int[] gas, int[] cost) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int total = 0; 6 int su... 阅读全文
posted @ 2013-11-09 15:41 JasonChang 阅读(264) 评论(0) 推荐(0) 编辑

摘要: 两遍遍历,使得左右邻居都合法 1 public class Solution { 2 public int candy(int[] ratings) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int[] candy = new int[ratings.length]; 6 int count = 0; ... 阅读全文
posted @ 2013-11-09 15:05 JasonChang 阅读(172) 评论(0) 推荐(0) 编辑

摘要: fastrunner and slowrunner trick 1 public class Solution { 2 public ListNode detectCycle(ListNode head) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 ListNode fastrunner = head; 6 ... 阅读全文
posted @ 2013-11-09 07:38 JasonChang 阅读(190) 评论(0) 推荐(0) 编辑

摘要: 将midnode后面的node的指针反转,再从头尾两边同时遍历注意midnode的next设为null 1 public class Solution { 2 public void reorderList(ListNode head) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int count = 0; 6 ... 阅读全文
posted @ 2013-11-09 07:32 JasonChang 阅读(224) 评论(0) 推荐(0) 编辑

摘要: recursion 1 public class Solution { 2 public ArrayList preorderTraversal(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 trave... 阅读全文
posted @ 2013-11-09 05:47 JasonChang 阅读(203) 评论(0) 推荐(0) 编辑

2013年11月8日

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

上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 18 下一页