Node *flatten(Node *head) {
    Node *it = head;
    stack<Node *> stack1;
    while (it) {
        if (it->child) {
             stack1.push(it->next);
                it->next = it->child;
                it->child->prev = it;
                it->child = nullptr;
            } else if (!it->next && !stack1.empty()) {
                it->next = stack1.top();
                if (it->next)
                    it->next->prev = it;
                stack1.pop();
            }
            it = it->next;
        }
        return head;
    }

相关文章:

  • 2021-10-14
  • 2021-10-21
  • 2022-12-23
  • 2021-06-22
猜你喜欢
  • 2021-11-11
  • 2021-11-05
  • 2021-08-23
  • 2021-11-01
  • 2021-07-01
  • 2021-11-30
  • 2021-11-29
相关资源
相似解决方案