Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- knakul853
- */
- class Solution {
- public:
- Node* flatten(Node* head) {
- Node* cur = head;
- while(cur){
- if(!cur->child){
- cur = cur->next;
- continue;
- }
- else{
- Node* pre = cur->next;
- Node* temp = cur->child;
- while(temp->next)
- {
- temp = temp->next;
- }
- temp->next = pre;
- if(pre) pre->prev = temp;
- cur->next = cur->child;
- cur->child->prev = cur;
- cur->child = NULL;
- cur = cur->next;
- }
- }
- return head;
- }
- };
Add Comment
Please, Sign In to add comment