image.png
    解析:使用指针来做

    1. class Solution {
    2. public ListNode reverseList(ListNode head) {
    3. if (head==null) {
    4. return null;
    5. }
    6. ListNode p=head;
    7. ListNode q=p.next;
    8. p.next=null;
    9. while (q!=null) {
    10. ListNode r=q.next;
    11. q.next=p;
    12. p=q;
    13. q=r;
    14. }
    15. return p;
    16. }
    17. }