反转单链表_JAVA

class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        ListNode* prev = NULL; //前指针节点
        ListNode* curr = head; //当前指针节点
        //每次循环,都将当前节点指向它前面的节点,然后当前节点和前节点后移
        while (curr != NULL) {
            ListNode* nextTemp = curr->next; //临时节点,暂存当前节点的下一节点,用于后移
            curr->next = prev; //将当前节点指向它前面的节点
            prev = curr; //前指针后移
            curr = nextTemp; //当前指针后移
        }
        return prev;
    }
};