JasonChang

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

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) 编辑