3 ms·
Wait, inverting a tree is a real thing? What does that even mean? All the terminal leaf nodes become roots? That can't be right. I thought part of the joke w
by recursive 5y ago
Wait, inverting a tree is a real thing? What does that even mean? All the terminal leaf nodes become roots? That can't be right. I thought part of the joke was that it was impossible.
- deleted 5y ago[deleted]
- eunoia 5y agoHorizontal inversion (mirror). I was equally confused though the first time I was asked lol.
- recursive 5y agoI would have called it "reversing", but I guess that sounds less technical. Now I'm confused, just in a different way. There's no obscure algorithm for this, just maybe 4 straight-forward lines, depending on language. I guess it tests whether you've ever heard of recursion. I thought the meme depended on it being some obscure, difficult, and irrelevant thing.
- moron4hire 5y agoWell, now you know. It's a meme that has become its own meta-meme.
- Arcuru 5y agoThe root is still the root, but everything else is just flipped: https://leetcode.com/problems/invert-binary-tree/ https://leetcode.com/problems/invert-binary-tree/ It is also extremely simple: TreeNode* invertTree(TreeNode* root) { if (root) { invertTree(root->left); invertTree(root->right); std::swap(root->left, root->right); } return root; }