• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
UsSam
博客园 | 首页 | 新随笔 | 新文章 | 联系 | 订阅 订阅 | 管理

2014年3月12日

【Leetcode】Balanced Binary Tree
摘要: 题目:Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofeverynode never differ by more than 1.解题思路1(下面给出两种代码实现,代码1和代码2):采用递归的方法,对每一层的节点进行遍历,从叶子节点开始回溯,并从下往上判断每一层的各个是否满足平衡树的条件,并得到以该节 阅读全文
posted @ 2014-03-12 19:20 UsSam 阅读(122) 评论(0) 推荐(0)
 
【Leetcode】Symmetric Tree
摘要: 题目:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the following is not: 1 / \ 2 2 \ \ 3 3Note:Bonus points if you could solve it both recursively and iter... 阅读全文
posted @ 2014-03-12 15:04 UsSam 阅读(91) 评论(0) 推荐(0)
 
【Leetcode】Same Tree
摘要: 题目: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.解题思路:对两棵树进行遍历即可,这里采用先序遍历的方法。代码:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *... 阅读全文
posted @ 2014-03-12 11:28 UsSam 阅读(136) 评论(0) 推荐(0)
 
 

公告


博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3