Skip to content

Commit

Permalink
Merge pull request #6982 from Tushar1323/main
Browse files Browse the repository at this point in the history
Depth_of_Binarytree
  • Loading branch information
ossamamehmood authored Oct 31, 2023
2 parents d808d72 + c998fd0 commit 6f75183
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Binary Tree/maxDepth.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
using namespace std;

struct Node
{
int data;
Node *left;
Node *right;
Node(int val)
{
data = val;
left = nullptr;
right = nullptr;
}
};

int maxDepth(Node *root)
{
if(root==NULL)
return 0;

return max(maxDepth(root->left), maxDepth(root->right)) + 1;
}

int main()
{

return 0;
}
35 changes: 35 additions & 0 deletions Binary Tree/minDepth.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
using namespace std;

struct Node
{
int data;
Node *left;
Node *right;
Node(int val)
{
data = val;
left = nullptr;
right = nullptr;
}
};

int minDepth(Node *root)
{
if(root==NULL)
return 0;

if(root->left==NULL)
return minDepth(root->right) + 1;

if(root->right==NULL)
return minDepth(root->left) + 1;

return min(minDepth(root->left), minDepth(root->right)) + 1;
}

int main()
{

return 0;
}

0 comments on commit 6f75183

Please sign in to comment.