题目链接
题目:给出两棵树,问能不能通过翻转(互换)左右孩子节点而互相转化
思路:递归进行比较,第一棵树的左孩子和第二棵数的左孩子,第一棵树的右孩子和第二棵数的右孩子 或者 第一棵树的左孩子和第二棵数的右孩子,第一棵树的右孩子和第二棵数的左孩子。

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode(int x) { val = x; }* }*/
class Solution {public boolean flipEquiv(TreeNode root1, TreeNode root2) {if(root1 == null || root2 == null){return root1 == root2;}if(root1.val != root2.val){return false;}return flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right) || flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left);}
}

leetcode951. Flip Equivalent Binary Trees相关推荐

  1. Rosalind第88题:Counting Rooted Binary Trees

    Problem As in the case of unrooted trees, say that we have a fixed collection of  taxa labeling the  ...

  2. LeetCode之All Possible Full Binary Trees(Kotlin)

    问题: A full binary tree is a binary tree where each node has exactly 0 or 2 children. Return a list o ...

  3. Tweaked Identical Binary Trees - Medium

    Determine whether two given binary trees are identical assuming any number of 'tweak's are allowed. ...

  4. 17. Merge Two Binary Trees 融合二叉树

    [抄题]: Given two binary trees and imagine that when you put one of them to cover the other, some node ...

  5. LeetCode 617. Merge Two Binary Trees

    题目: Given two binary trees and imagine that when you put one of them to cover the other, some nodes ...

  6. C#LeetCode刷题之#617-合并二叉树​​​​​​​​​​​​​​(Merge Two Binary Trees)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4096 访问. 给定两个二叉树,想象当你将它们中的一个覆盖到另一个 ...

  7. Given two binary trees, write a function to check if they areequal or not.

    Given two binary trees, write a function to check if they areequal or not. Two binary trees are cons ...

  8. (数据结构基础)Among the following threaded binary trees (the threads are represented by dotted curves),……

    当年学这些的时候真的是苦于没有人讲,现在复习考研,我会见到这种题就写下来,学弟学妹们欢迎点个关注,最近也在创业想实习的可以找我联系:没看懂的话是我表述有问题,欢迎指出和私戳. Among the fo ...

  9. 617.Merge Two Binary Trees(合并两棵树)

    Given two binary trees and imagine that when you put one of them to cover the other, some nodes of t ...

最新文章

  1. linux查看CPU信息
  2. Android 有些机型hint不显示
  3. 文件夹操作之判断是否存在(Directory)
  4. Transact-SQL 示例 - 如何在拼接的动态sql内调用外部变量
  5. mysql动态配置数据源_Spring整合Mybatis实现动态数据源切换教程配置
  6. 下班以后看什么,决定你人生的高度
  7. 博士笔记 | 周志华《机器学习》手推笔记第二章-模型评估与选择
  8. SAP HANA Backup and Recovery
  9. Linux 内核 链表 的简单模拟(1)
  10. java求生序列_Java 经典面试题:聊一聊 JUC 下的 LinkedBlockingQueue_绝地求生黑号,dnf辅助...
  11. linux下常用vim命令
  12. HSF (RPC远程调用框架)
  13. java 小说系统_java 实现小说管理系统
  14. JVM性能调优(一)(JVM参数详解、内存分析等)
  15. MySQL技术内幕InnoDB存储引擎
  16. 电脑上的记事本便签纸怎么用
  17. overflow and underflow
  18. 普鸥知产|亚马逊品牌备案被判“滥用行为”无法备案如何解决?
  19. C语言——求三个数中最大值(6种方法)
  20. matlab图像增强实验总结,图像处理实验报告

热门文章

  1. [HNOI2008]水平可见直线 半平面交
  2. 05使用jmeter里调试一个下单接口
  3. 圣思园java se培训总结(58-)(java1.5新特性,可变参数,包装类)
  4. 30个Oracle语句优化规则详解(1)
  5. Tomcat源码学习(9)-How Tomcat works(转)
  6. 使用Blend开发Silverlight VSM
  7. 【JavaScript 笔记 】— 基础语法(数据类型、字符串、数组、对象、Map、Set、iterable、函数基础)
  8. 【网络安全工程师面试合集】—不要随便浏览一些奇怪的小网站哦
  9. [转]Ubuntu terminator 无法打开解决方案
  10. [转]从根上理解高性能、高并发:深入计算机底层,理解线程与线程池