# 第一题 移除链表元素

``````class Solution {
public ListNode removeElements(ListNode head, int val) {
while(cur.next!=null){
if(cur.next.val==val){
cur.next=cur.next.next;
}else{
cur=cur.next;
}
}
}
}
``````

# 第二题 反转链表

``````class Solution {
ListNode pre =null;
while(cur!=null){
ListNode next=cur.next;
cur.next=pre;
pre=cur;
cur=next;
}

return pre;
}
}
``````

# 第三题 链表的中心结点

``````class Solution {
while(q!=null&&q.next!=null){
q=q.next.next;
p=p.next;
}
return p;

}
}
``````

# 第四题 倒数第k个结点

1,{1,2,3,4,5}

{5}

``````public class Solution {
public ListNode FindKthToTail(ListNode head,int k) {

int count=0;
int x=0;

while(cur!=null){

cur=cur.next;
count++;
}
if(k<0||k>count){
return null;
}
while(pre!=null){
if(x==count-k){
break;
}else{
pre=pre.next;
x++;
}
}
return pre;
}
}
``````

``````public class Solution {
public ListNode FindKthToTail(ListNode head,int k) {
for(int i = 0; i < k; i++) {
if (p != null) {
p= p.next;
} else {
return null;
}
}
while(p!=null){
p=p.next;
q=q.next;
}
return q;
}
}
``````

# 第五题 合并两个有序链表

``````class Solution {
public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
while (l1 != null && l2 != null) {
if (l1.val < l2.val) {
cur.next = l1;
cur = cur.next;
l1 = l1.next;
} else {
cur.next = l2;
cur = cur.next;
l2 = l2.next;
}
}
// 任一为空，直接连接另一条链表
if (l1 == null) {
cur.next = l2;
} else {
cur.next = l1;
}
}
}
``````

# 第六题 链表分割

``````public class Partition {
public ListNode partition(ListNode pHead, int x) {
}
newh = newh.next;
}else{
flagh = flagh.next;
}
}
}
}
``````

# 第七题 判断是否回文

1->2->2->1

``````public class PalindromeList {
// write code here
while(fast!=null && fast.next!=null) {
fast = fast.next.next;
slow = slow.next;
}
ListNode cur=slow.next；
while(cur!=null){
ListNode curNext=cur.next;
cur.next=slow;
slow=cur;
cur=curNext;
}
//3.一个从前往后，一个从后往前  如果相遇，则证明回文
return false;
}
return true;
}
slow=slow.next;
}
return true;
}
``````

# 第八题 相交链表

``````public class Solution {
return null;
}
while (last.next != null) {
last = last.next;
}

while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
if (slow == fast) {
while (slow != fast) {
slow = slow.next;
fast = fast.next;
}
last.next = null;
return fast;
}
}
last.next = null;
return null;
}
}
``````

THE END