# 代码随想录算法训练营第四天| 24. 两两交换链表中的节点 19.删除链表的倒数第N个节点 面试题 02.07. 链表相交 142.环形链表II()-其他

## 代码随想录算法训练营第四天| 24. 两两交换链表中的节点 19.删除链表的倒数第N个节点 面试题 02.07. 链表相交 142.环形链表II()

### 24. 两两交换链表中的节点

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

### 19.删除链表的倒数第N个节点

``````class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
for (int i = 0; i < n; i++) {
fast = fast.next;
}
while (fast.next != null) {
fast = fast.next;
slow = slow.next;
}
slow.next = slow.next.next;
}
}
``````

### 面试题 02.07. 链表相交

``````public class Solution {
return null;
}

} else {
}
} else {
}
}
}
}
``````

### 142. 环形链表 II

``````public class Solution {
boolean isMeet = false;

return null;
}
}
while (fast != slow && fast != null && fast.next != null) {
fast = fast.next.next;
slow = slow.next;
if (fast == slow) {
isMeet = true;
}
}
if (isMeet) {
while (slow != fast) {
slow = slow.next;
fast = fast.next;
}
}else{
fast = null;
}
return fast;

}
}
``````
————————

### 24. 两两交换链表中的节点

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

### 19.删除链表的倒数第N个节点

``````class Solution {
public ListNode removeNthFromEnd(ListNode head, int n) {
for (int i = 0; i < n; i++) {
fast = fast.next;
}
while (fast.next != null) {
fast = fast.next;
slow = slow.next;
}
slow.next = slow.next.next;
}
}
``````

### 面试题 02.07. 链表相交

``````public class Solution {
return null;
}

} else {
}
} else {
}
}
}
}
``````

### 142. 环形链表 II

``````public class Solution {
boolean isMeet = false;

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