Mid From PDF Coding C# Coding Interview

Check if two trees are identical?

bool IsIdentical(TreeNode p, TreeNode q) {

if (p == null && q == null) return true;
if (p == null || q == null) return false;
if (p.val != q.val) return false;
return IsIdentical(p.left, q.left) && IsIdentical(p.right,

q.right);

}

Explanation:

Recursive check values and structure for equality.

More from C# Programming Tutorial

All questions for this course
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details