leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0206.cpp (278B)


      1 class Solution {
      2   public:
      3     ListNode *reverseList(ListNode *head) {
      4         ListNode *p, *q, *r;
      5 
      6         p = head, q = nullptr;
      7         while (p) {
      8             r = q;
      9             q = p;
     10             p = p->next;
     11             q->next = r;
     12         }
     13 
     14         return q;
     15     }
     16 };