8000 auto commit · iCodingStar/Interview-Notebook@e8a0cd6 · GitHub
[go: up one dir, main page]

65D7 Skip to content

Commit e8a0cd6

Browse files
committed
auto commit
1 parent c5491dd commit e8a0cd6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

notes/剑指 offer 题解.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* [第三章 高质量的代码](#第三章-高质量的代码)
2121
* [16. 数值的整数次方](#16-数值的整数次方)
2222
* [17. 打印从 1 到最大的 n 位数](#17-打印从-1-到最大的-n-位数)
23+
* [18.1 在 O(1) 时间内删除链表节点](#181-在-o1-时间内删除链表节点)
2324
* [18.2 删除链表中重复的结点](#182-删除链表中重复的结点)
2425
* [19. 正则表达式匹配](#19-正则表达式匹配)
2526
* [20. 表示数值的字符串](#20-表示数值的字符串)
@@ -615,6 +616,25 @@ private void printNumber(char[] number) {
615616
}
616617
```
617618

619+
## 18.1 在 O(1) 时间内删除链表节点
620+
621+
```java
622+
public ListNode deleteNode(ListNode head, ListNode tobeDelete) {
623+
if (head == null || head.next == null || tobeDelete == null) return null;
624+
if (tobeDelete.next != null) {
625+
// 要删除的节点不是尾节点
626+
ListNode next = tobeDelete.next;
627+
tobeDelete.val = next.val;
628+
tobeDelete.next = next.next;
629+
} else {
630+
ListNode cur = head;
631+
while (cur.next != tobeDelete) cur = cur.next;
632+
cur.next = null;
633+
}
634+
return head;
635+
}
636+
```
637+
618638
## 18.2 删除链表中重复的结点
619639

620640
```java

0 commit comments

Comments
 (0)
0