C++ Good Taste Code

reorder-list

http://www.nowcoder.com/questionTerminal/3d281dc0b3704347846a110bf561ef6b

class Solution {
public:
    void reorderList(ListNode *head) {
        if (head == NULL || head->next == NULL || head->next->next == NULL)
            return;
        ListNode** left = &head;
        ListNode** right = left;
        while (*left != NULL && (*left)->next != NULL) {
            while (*right != NULL && (*right)->next != NULL) {
                right = &(*right)->next;
            }
            ListNode* tail = *right;
            *right = NULL;
            tail->next = (*left)->next;
            (*left)->next = tail;
            left = &(*left)->next->next;
            right = left;
        }
        return;
    }
};
全部评论
请问这个算法一定要用到二级指针吗?是不是一级指针也可以实现呢?
点赞 回复 分享
发布于 2021-04-28 11:09

相关推荐

评论
10
3
分享
牛客网
牛客企业服务