Skip to content

Instantly share code, notes, and snippets.

@vanbrabantf
Created April 2, 2021 14:24
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 vanbrabantf/3b0b799543d5944786184712d7c8a3a5 to your computer and use it in GitHub Desktop.
Save vanbrabantf/3b0b799543d5944786184712d7c8a3a5 to your computer and use it in GitHub Desktop.
<?php
public function invert(?Node $tree): ?Node
{
if ($tree === null) {
return null;
}
$right = $this->invert($tree->getLeft());
$left = $this->invert($tree->getRight());
return new Node($tree->getValue(), $left, $right);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment