(head)
| 17 | // 直至空。 |
| 18 | // PS,链表操作好麻烦。 |
| 19 | var reverseList = function(head) { |
| 20 | |
| 21 | let newHead = null |
| 22 | |
| 23 | // 先不判断进行一次交换 |
| 24 | let nHead = head |
| 25 | if (!nHead) { |
| 26 | return null |
| 27 | } |
| 28 | let next = nHead.next |
| 29 | if (!next) { |
| 30 | return nHead |
| 31 | } |
| 32 | let lNext = next.next |
| 33 | |
| 34 | next.next = nHead |
| 35 | nHead.next = null |
| 36 | |
| 37 | newHead = next |
| 38 | |
| 39 | while (nHead && next && next.next) { |
| 40 | nHead = lNext |
| 41 | if (!nHead) { |
| 42 | return newHead |
| 43 | } |
| 44 | |
| 45 | next = nHead.next |
| 46 | |
| 47 | if (!next) { |
| 48 | nHead.next = newHead |
| 49 | return nHead |
| 50 | } |
| 51 | lNext = next.next |
| 52 | |
| 53 | next.next = nHead |
| 54 | nHead.next = newHead |
| 55 | |
| 56 | newHead = next |
| 57 | |
| 58 | } |
| 59 | }; |
nothing calls this directly
no outgoing calls
no test coverage detected