Skip to content

Instantly share code, notes, and snippets.

@tanzaku
Created November 29, 2016 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanzaku/d6c73ca4cd1757906ddd62d1ac60df90 to your computer and use it in GitHub Desktop.
Save tanzaku/d6c73ca4cd1757906ddd62d1ac60df90 to your computer and use it in GitHub Desktop.
public static Node merge(Node l, Node r) {
if (l == null || r == null) return l == null ? r : l;
Node v = peekFirst(r); // O(h)
return join(l, v, removeFirst(r)); // O(h(l) - h(r))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment