LeetCode Çözümleri – 226. Invert Binary Tree

LeetCode içerisinde bulunan “Invert Binary Tree” sorusunun açıklaması ve çözümü. Bu soruda size verilen bir binary tree‘i tersine çevirmeniz isteniyor. Binary tree yapısı ile en sık karşılaşabileceğiniz soru tipi. Rekürsif yapı ile mantığını oturtursanız çok kolay anlaşılabiliyor.

✨ Binary tree nedir?

In computer science, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child.

➡️ Binary Tree Data Structure: https://www.geeksforgeeks.org/binary-tree-data-structure/

➡️ Binary Trees: https://www.cmpe.boun.edu.tr/~akin/cmpe223/chap4.htm

➡️ Binary Trees by Nick Parlante: http://cslibrary.stanford.edu/110/BinaryTrees.html

✨ LeetCode 226. Invert Binary Tree: https://leetcode.com/problems/invert-binary-tree/

➡️ Problem açıklaması:

Invert a binary tree.

Example:

Input:

4

/ \

2 7

/ \ / \

1 3 6 9

Output:

4

/ \

7 2

/ \ / \

9 6 3 1

Trivia:

This problem was inspired by this original tweet (https://twitter.com/mxcl/status/608682016205344768) by Max Howell:

Google: 90% of our engineers use the software you wrote (Homebrew), but you can’t invert a binary tree on a whiteboard so f*** off.