DFS
我真的不会Coding
任何时候努力都不晚,要保持自信
展开
-
存储路径:递归或者是DFSleetcode113. Path Sum II路径之和II递归DFS
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. Note: A leaf is a node with no children. Example: Given the below binary tree and sum = 22, ...原创 2018-08-03 15:20:29 · 163 阅读 · 0 评论 -
判断一棵二叉树是否是平衡二叉树
输入一棵二叉树,判断该二叉树是否是平衡二叉树。 首先,平衡二叉树的定义:/*平衡二叉搜索树(Balanced Binary Tree)具有以下性质: 它是一棵空树或它的左右两个子树的高度差的绝对值不超过1,并且左右两个子树都是一棵平衡二叉树*/ 所以我想到的是递归的方法,判断左右的高度差。 第一种方法用来判断该二叉树是否为平衡二叉树 struct TreeNo...原创 2018-08-16 10:26:54 · 283 阅读 · 0 评论 -
LeetCode 547. Friend Circles 合并集
There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C, then ...原创 2018-08-26 22:28:00 · 112 阅读 · 0 评论