2019年3月4日

两个链表的第一个公共结点

摘要: 我的思路:先求长度,每个长度长的遍历一次长度短的, 后看评论理解题意:第一个公共结点后面的都相同,所以可以先走长-短的差再比较。 public class Solution { public ListNode FindFirstCommonNode(ListNode pHead1, ListNode 阅读全文

posted @ 2019-03-04 21:12 q2013 阅读(117) 评论(0) 推荐(0) 编辑

合并两个排序的链表

摘要: public class Solution { public ListNode Merge(ListNode list1,ListNode list2) { if(list1 == null && list2 == null) return null; else{ ListNode list3 = 阅读全文

posted @ 2019-03-04 20:03 q2013 阅读(80) 评论(0) 推荐(0) 编辑

链表中倒数第k个结点

摘要: 思路:两个指针,一个先指到k,两个一起往后移,一个指到尾时另一个在倒数k处。 public class Solution { public ListNode FindKthToTail(ListNode head,int k) { ListNode p = head; ListNode q = he 阅读全文

posted @ 2019-03-04 17:16 q2013 阅读(63) 评论(0) 推荐(0) 编辑

反转链表

摘要: public class Solution { public ListNode ReverseList(ListNode head) { if(head == null || head.next == null)//考虑特殊情况 return head; ListNode pre = null; / 阅读全文

posted @ 2019-03-04 16:29 q2013 阅读(95) 评论(0) 推荐(0) 编辑

导航