摘要:
public class Solution { public ArrayList rightSideView(TreeNode root) { // 层遍历,利用queue http://bookshadow.com/weblog/2015/04/03/leetcode-bina... 阅读全文
摘要:
折腾出来比较费劲,但是巩固了linked list reverse的概念如果有 pre -> 1 ->2 ->3 ->4 ->end返回的reverse是 原来的pre.next 也就是最后reversed 了以后的list: pre ->4 ->3 ->2 ->1 ->end的那个1,在这里,re... 阅读全文
摘要:
Reverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.No... 阅读全文
摘要:
关键是想好swap 的function怎么写我的做法是输入输出两支点pre& end,中间的两个node swappublic class Solution { public ListNode swapPairs(ListNode head) { if(head==null ||... 阅读全文
摘要:
也很简单,关键是掌握mergeSort见ref http://www.cnblogs.com/springfor/p/3869217.html, 摘抄这里来复习一下Merge Sort(对于数组操作),参考Wikipedia:归并操作(merge),也叫归并算法,指的是将两个已经排序的序列合并成一个... 阅读全文
摘要:
很简单public class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { ListNode h = new ListNode(-1); ListNode l3 = h; ... 阅读全文
摘要:
很简单的一道题,隐含条件要问清楚, n> len的时候就删除首个public class Solution { public ListNode removeNthFromEnd(ListNode head, int n) { if(head==null) return null;... 阅读全文
摘要:
public class Solution { // http://www.cnblogs.com/springfor/p/3864493.html public ListNode addTwoNumbers(ListNode l1, ListNode l2) { List... 阅读全文
摘要:
public class Solution { public ArrayList> fourSum(int[] num, int target) { // the same as 3sum ArrayList> res = new ArrayList>(); ... 阅读全文
摘要:
public int threeSumClosest(int[] num, int target) { //int d = 0; if(num==null || num.length0) low++; if(M... 阅读全文