Tag Archives: binary tree

LeetCode Çözümleri – 101. Symmetric Tree

LeetCode içerisinde bulunan “Symmetric Tree” sorusunun açıklaması ve çözümü. Size root’u verilen bir binary tree‘nin merkezine göre simetrik olup olmadığını bulmanız isteniyor.

► LeetCode 101. Symmetric Tree: https://leetcode.com/problems/symmetric-tree/

► Problem açıklaması:

Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).

Input: root = [1,2,2,3,4,4,3]

Output: true

Input: root = [1,2,2,null,3,null,3]

Output: false

Constraints:

The number of nodes in the tree is in the range [1, 1000].

-100 <= Node.val <= 100

Follow up: Could you solve it both recursively and iteratively?

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.