Thursday, October 2, 2014

Symmetric Tree

Problem

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).

For example, this binary tree is symmetric:
But the following is not:

Idea

dfs, 对于每个iteration, 两个pointer分别遍历right_sub和left_sub。 然后比较。

Solution


No comments:

Post a Comment