Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 548 Bytes

File metadata and controls

27 lines (20 loc) · 548 Bytes

Tags: tree dfs

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);
  }
};