1. Problem Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. 2. Idea We can determine whether two trees are the same recursively. That is, they are the same if and only if they roots (if any) have the same value, and their left subtrees and right subtrees are the same, respectively. 3. Implementation Java package me.darrensunny.leetcode; /** * LeetCode - Same Tree * Created by Darren on 14-5-23.
Read full article from LeetCode - Same Tree | Darren's Blog
No comments:
Post a Comment