public class Solution {
public ListNode ReverseList(ListNode head) {
if(head == null) {
return null;
}
ListNode pre = null;
ListNode next = null;
while(head != null) {
next = head.next;
head.next = pre;
pre = head;
head = next;
}
return pre;
}
}
public class Solution {
public ListNode Merge(ListNode list1,ListNode list2) {
if(list1 == null || list2 == null) {
return list1 != null ? list1 : list2;
}
ListNode head = null;
if(list1.val > list2.val) {
head = list2;
head.next = Merge(list1, list2.next);
} else {
head = list1;
head.next = Merge(list1.next, list2);
}
return head;
}
}
public class Solution {
public ListNode FindKthToTail(ListNode head,int k) {
if(head == null || k <= 0) {
return null;
}
ListNode fast = head;
ListNode slow = head;
for(int i = 0; i < k-1; i++) {
if(fast.next == null) {
return null;
}
fast = fast.next;
}
while(fast.next != null) {
fast = fast.next;
slow = slow.next;
}
return slow;
}
}