leetcode

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

0092.cpp (532B)


      1 class Solution {
      2   public:
      3     ListNode *reverseBetween(ListNode *head, int left, int right) {
      4         ListNode top;
      5         top.next = head;
      6         ListNode *prev = ⊤
      7 
      8         for (int i = 1; i < left; i++)
      9             prev = prev->next;
     10 
     11         ListNode *crnt = prev->next;
     12         for (int i = 0; i < right - left; i++) {
     13             ListNode *tmp = prev->next;
     14             prev->next = crnt->next;
     15             crnt->next = crnt->next->next;
     16             prev->next->next = tmp;
     17         }
     18 
     19         return top.next;
     20     }
     21 };