category-wise-problems

contains category wise problems(data structures, competitive) of popular platforms.

View the Project on GitHub mayankdutta/category-wise-problems

104. Maximum Depth of Binary Tree

can do via

iterative ```cpp class Solution { public: int maxDepth(TreeNode* root) { int ans = 0; queue<TreeNode*> qu; if (root == nullptr) return 0; qu.push(root); while (!qu.empty()) { int Size = qu.size(); ans ++; for (int i = 0; i < Size; i++) { auto top = qu.front(); qu.pop(); if (top -> left) qu.push(top -> left); if (top -> right) qu.push(top -> right); } } return ans; } }; ```
recursive ```cpp class Solution { public: int maxDepth(TreeNode* root) { auto fun = [&](const auto& self, const auto& root) -> int { return root == nullptr ? 0 : max(self(self, root -> right), self(self, root -> left)) + 1; }; return fun(fun, root); } }; ```