Advertisement
tuki2501

test.py

Dec 17th, 2022
1,186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. Huy
  2. class Solution {
  3. public:
  4.     ListNode* reverseList(ListNode* head) {
  5.         ListNode *curr = head;
  6.         ListNode *next = head;
  7.         ListNode *temp = head;
  8.         ListNode *prev = NULL;
  9.         int numOfNode = 0;
  10.  
  11.         while(temp->next != NULL) {
  12.             temp = temp->next;
  13.             numOfNode++;
  14.         }
  15.  
  16.         if (numOfNode != 0) {
  17.             while (curr != NULL) {
  18.                 next = curr->next;
  19.                 curr->next = prev;
  20.                 prev = curr;
  21.                 curr = next;
  22.             }
  23.         } else {
  24.             return;
  25.         }
  26.         return;
  27.     }
  28. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement