{"size": 903, "ext": "js", "max_stars_repo_path": "problems/092_reverse-linked-list-ii/index.js", "max_stars_repo_name": "sakuraiki/leetcode", "max_stars_repo_stars_event_min_datetime": "2016-03-19T02:49:36.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-12T18:38:55.000Z", "max_issues_repo_path": "problems/092_reverse-linked-list-ii/index.js", "max_issues_repo_name": "sakuraiki/leetcode", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "problems/092_reverse-linked-list-ii/index.js", "max_forks_repo_name": "sakuraiki/leetcode", "max_forks_repo_forks_event_min_datetime": "2016-04-17T05:55:44.000Z", "max_forks_repo_forks_event_max_datetime": "2021-01-27T07:48:56.000Z"}
{"max_stars_count": 158, "max_issues_count": null, "max_forks_count": 35, "avg_line_length": 20.0666666667, "max_line_length": 77, "alphanum_fraction": 0.5481727575}
/**
 * Problem: https://leetcode.com/problems/reverse-linked-list-ii/description/
 */
/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @param {number} m
 * @param {number} n
 * @return {ListNode}
 */
var reverseBetween = function(head, m, n) {
  var root = {
    value : undefined,
    next  : head
  };
  var front = root, tail = root, tmpHead = root, tmp;
  for (var i = 0; i < m - 1; ++i) {
    tmpHead = tmpHead.next;
  }
  for (var i = 0; i < m; ++i) {
    front = front.next;
  }
  for (var i = 0; i <= n; ++i) {
    tail = tail.next;
  }
  console.log('front: ', front, 'tail: ', tail);

  for (var i = m; i <= n; ++i) {
    tmp = front.next;
    front.next = tail;
    tail = front;
    front = tmp;
  }
  tmpHead.next = tail;

  return root.next;
};
module.exports = reverseBetween;
