import { ListNode } from './LinkList' ; param { ListNode } head return { ListNode } function ReverseList ( head ) { let headNode = head ; let preNode = null ; let next = null ; while ( headNode ) { next = headNode . next ; headNode . next = preNode ; preNode = headNode ; headNode = next ; } return preNode ; } param { ListNode } head param { number } m param { number } n return { ListNode } function ReverseBetween ( head , m , n ) { if ( ! head || head . next == null ) { return head ; } let current = head ; let prev = null ; while ( m > 1 ) { prev = current ; current = current . next ; m -- ; n -- ; } let prevTail = prev ; let theTail = current ; let theNext = null ; while ( n > 0 ) { theNext = current . next ; current . next = prev ; prev = current ; current = theNext ; n -- ; } if ( prevTail === null ) { head = prev ; } else { prevTail . next = prev ; } theTail . next = current ; return head ; } export { ReverseList , ReverseBetween } ;