Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 528 Bytes

same_tree.md

File metadata and controls

25 lines (19 loc) · 528 Bytes

100. Same Tree, Easy

  • again dfs concept same as of depth of the tree was used.
implementation
class Solution {
  public:
  bool isSameTree(TreeNode* p, TreeNode* q) {
    if (p == nullptr and q == nullptr) 
      return true;
    if (p == nullptr or q == nullptr) 
      return false;

    return      (p -> val == q -> val)  && 
      isSameTree(p -> left,  q -> left) && 
      isSameTree(p -> right, q -> right);
  }
};