@@ -321,7 +321,7 @@ \section{单链表} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321
321
struct ListNode {
322
322
int val;
323
323
ListNode *next;
324
- ListNode(int x) : val(x), next(NULL ) { }
324
+ ListNode(int x) : val(x), next(nullptr ) { }
325
325
};
326
326
\end {Code }
327
327
@@ -353,15 +353,15 @@ \subsubsection{代码}
353
353
ListNode* pre = head;
354
354
ListNode *pa = l1, *pb = l2;
355
355
int carry = 0;
356
- while (pa != NULL || pb != NULL ) {
357
- int av = pa == NULL ? 0 : pa->val;
358
- int bv = pb == NULL ? 0 : pb->val;
356
+ while (pa != nullptr || pb != nullptr ) {
357
+ int av = pa == nullptr ? 0 : pa->val;
358
+ int bv = pb == nullptr ? 0 : pb->val;
359
359
ListNode* node = new ListNode((av + bv + carry) % 10);
360
360
carry = (av + bv + carry) / 10;
361
361
pre->next = node; // 尾插法
362
362
pre = pre->next;
363
- pa = pa == NULL ? NULL : pa->next;
364
- pb = pb == NULL ? NULL : pb->next;
363
+ pa = pa == nullptr ? nullptr : pa->next;
364
+ pb = pb == nullptr ? nullptr : pb->next;
365
365
}
366
366
if (carry > 0)
367
367
pre->next = new ListNode(1);
@@ -388,9 +388,9 @@ \subsubsection{描述}
388
388
Reverse a linked list from position $ m$ to $ n$ . Do it in-place and in one-pass.
389
389
390
390
For example:
391
- Given \code {1->2->3->4->5->NULL }, $ m$ = 2 and $ n$ = 4,
391
+ Given \code {1->2->3->4->5->nullptr }, $ m$ = 2 and $ n$ = 4,
392
392
393
- return \code {1->4->3->2->5->NULL }.
393
+ return \code {1->4->3->2->5->nullptr }.
394
394
395
395
Note:
396
396
Given m, n satisfy the following condition:
@@ -475,7 +475,7 @@ \subsubsection{代码}
475
475
class Solution {
476
476
public:
477
477
ListNode* partition(ListNode* head, int x) {
478
- if (head == NULL ) return head;
478
+ if (head == nullptr ) return head;
479
479
480
480
ListNode left_dummy(0); // 头结点
481
481
ListNode right_dummy(0); // 头结点
@@ -494,7 +494,7 @@ \subsubsection{代码}
494
494
}
495
495
496
496
left_cur->next = right_dummy.next;
497
- right_cur->next = NULL ;
497
+ right_cur->next = nullptr ;
498
498
499
499
return left_dummy.next;
500
500
}
@@ -533,10 +533,10 @@ \subsubsection{代码}
533
533
class Solution {
534
534
public:
535
535
ListNode *deleteDuplicates(ListNode *head) {
536
- if (head == NULL ) return NULL ;
536
+ if (head == nullptr ) return nullptr ;
537
537
ListNode * prev = head;
538
538
ListNode *cur = head->next;
539
- while (cur != NULL ) {
539
+ while (cur != nullptr ) {
540
540
if (prev->val == cur->val) {
541
541
ListNode* temp = cur;
542
542
cur = cur->next;
@@ -584,14 +584,14 @@ \subsubsection{代码}
584
584
class Solution {
585
585
public:
586
586
ListNode *deleteDuplicates(ListNode *head) {
587
- if (head == NULL ) return head;
587
+ if (head == nullptr ) return head;
588
588
589
589
ListNode dummy(INT_MIN); // 头结点
590
590
dummy.next = head;
591
591
ListNode *prev = &dummy, *cur = head;
592
- while (cur != NULL ) {
592
+ while (cur != nullptr ) {
593
593
bool duplicated = false;
594
- while (cur->next != NULL && cur->val == cur->next->val) {
594
+ while (cur->next != nullptr && cur->val == cur->next->val) {
595
595
duplicated = true;
596
596
ListNode *temp = cur;
597
597
cur = cur->next;
@@ -629,7 +629,7 @@ \subsubsection{描述}
629
629
Given a list, rotate the list to the right by $ k$ places, where $ k$ is non-negative.
630
630
631
631
For example:
632
- Given \code {1->2->3->4->5->NULL } and \code {k = 2}, return \code {4->5->1->2->3->NULL }.
632
+ Given \code {1->2->3->4->5->nullptr } and \code {k = 2}, return \code {4->5->1->2->3->nullptr }.
633
633
634
634
635
635
\subsubsection {分析 }
@@ -642,7 +642,7 @@ \subsubsection{代码}
642
642
class Solution {
643
643
public:
644
644
ListNode *rotateRight(ListNode *head, int k) {
645
- if (head == NULL || k == 0) return head;
645
+ if (head == nullptr || k == 0) return head;
646
646
647
647
int len = 1;
648
648
ListNode* p = head;
@@ -657,7 +657,7 @@ \subsubsection{代码}
657
657
p = p->next; //接着往后跑
658
658
}
659
659
head = p->next; // 新的首节点
660
- p->next = NULL ; // 断开环
660
+ p->next = nullptr ; // 断开环
661
661
return head;
662
662
}
663
663
};
0 commit comments