Update notes
This commit is contained in:
parent
eef2af7756
commit
d83eb02ae6
@ -1,4 +1,8 @@
|
||||
# Summary
|
||||
# 思路
|
||||
|
||||
- [深度优先遍历](./dfs.md)
|
||||
- [广度优先遍历](./bfs.md)
|
||||
|
||||
## 经典代码
|
||||
|
||||
- [合并两个有序链表](./merge_two_sorted_linked_lists.md)
|
||||
|
18
notes/src/merge_two_sorted_linked_lists.md
Normal file
18
notes/src/merge_two_sorted_linked_lists.md
Normal file
@ -0,0 +1,18 @@
|
||||
# 合并两个有序链表
|
||||
|
||||
```cpp
|
||||
ListNode* mergeTwoLists(ListNode *a, ListNode *b) {
|
||||
if ((!a) || (!b)) return a ? a : b;
|
||||
ListNode head, *tail = &head, *aPtr = a, *bPtr = b;
|
||||
while (aPtr && bPtr) {
|
||||
if (aPtr->val < bPtr->val) {
|
||||
tail->next = aPtr; aPtr = aPtr->next;
|
||||
} else {
|
||||
tail->next = bPtr; bPtr = bPtr->next;
|
||||
}
|
||||
tail = tail->next;
|
||||
}
|
||||
tail->next = (aPtr ? aPtr : bPtr);
|
||||
return head.next;
|
||||
}
|
||||
```
|
Loading…
Reference in New Issue
Block a user