Skip to content

prakash-2409/LeetCode

Repository files navigation

LeetCode

Just use my repo for referring your leetcode solution.

1. Invert binary tree

Given the root of a binary tree, invert the tree, and return its root.

Example 1:

alt text Input: root = [4,2,7,1,3,6,9] Output: [4,7,2,9,6,3,1] Example 2:

Input: root = [2,1,3] Output: [2,3,1] Example 3: alt text Input: root = [] Output: [] Submission: alt text

2. Maximum Depth of Binary Tree

Given the root of a binary tree, return its maximum depth.

A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

Example 1: Input: root = [3,9,20,null,null,15,7] Output: 3

Example 2: Input: root = [1,null,2] Output: 2

Approach: Using recursive DFS to calculate depth of left and right subtrees, then return max + 1. Runtime: 0 ms (Beats 100.00%)

3. Same Tree

Given the roots of two binary trees p and q, write a function to check if they are the same or not.

Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.

Example 1: Input: p = [1,2,3], q = [1,2,3] Output: true

Example 2: Input: p = [1,2], q = [1,null,2] Output: false

Approach: Three recursive checks - both null (true), one null (false), values differ (false). Then recursively verify left AND right subtrees match. Runtime: 0 ms (Beats 100.00%)

About

Just use my repo for referring your leetcode solution.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors