```
public class Solution {
public boolean isSymmetric(TreeNode root) {
long hash1 = Dfs(root, true);
long hash2 = Dfs(root, false);
return hash1 == hash2;
}
long Dfs(TreeNode node, boolean flag)
{
if(null == node) return 10007;
long result = flag ? Dfs(node.left, flag) * (node.val + 10007) + Dfs(node.right, flag) : Dfs(node.right, flag) * (node.val + 10007) + Dfs(node.left, flag);
return result;
}}
```