Well, leetcode doesn’t really like my answer but I think the overall approach is correct:

var flatten = function(head) {

let list = head;

// save the one that would have been next
let temp = list.next;
list.next = flatten(list.child);
list.next.prev = temp;

// get to the end of our flattened list that
// was appended and then add our original 'next'

list = list.next

list.next = temp;
temp.prev = list;

list = list.next;


return head

Written by

full-stackish developer, late bloomer coder and power google user

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store