码迷,mamicode.com
首页 >  
搜索关键字:treenode    ( 1958个结果
Java基础----ArrayList中的clear方法以及ArrayList对象
今天在做Leetcode 102. 二叉树的层序遍历 时, 不管怎么试,每一层的输出都为空,如下图: 上述结果所使用的代码如下。 1 public List<List<Integer>> levelOrder(TreeNode root) { 2 if(root == null) return nu ...
分类:编程语言   时间:2020-06-14 10:46:26    阅读次数:134
python 二叉树的遍历及常见操作
一、基础 1、 定义节点类 # Definition for a binary tree node. class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None 2、给定一张图 二、基础 ...
分类:编程语言   时间:2020-06-13 13:04:01    阅读次数:55
101.对称二叉树
题目描述: 给定一个二叉树,检查它是否是镜像对称的。例如,二叉树 [1,2,2,3,4,4,3] 是对称的。 DFS:递归,和100题相同的树类似,不过要注意是左右子树进行比较 //C //注意这个函数声明 bool isMirroTree(struct TreeNode* p, struct Tr ...
分类:其他好文   时间:2020-06-13 11:25:28    阅读次数:56
107.二叉树的遍历层次II
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = Nonefrom typing import Listclass Solution: # 迭代的想法 def levelOrderBot ...
分类:其他好文   时间:2020-06-13 00:42:24    阅读次数:46
100.相同的树
题目描述: 给定两个二叉树,编写一个函数来检验它们是否相同。如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。 深度优先遍历,递归或者用栈 //C //递归 bool isSameTree(struct TreeNode* p, struct TreeNode* q){ if(p = ...
分类:其他好文   时间:2020-06-12 14:24:15    阅读次数:43
【LeetCode】面试题32-2. 从上到下打印二叉树II
题目: 思路: 因为要求每层节点打印到一行,所以层次遍历时需要知道行的信息。个人思路通过两个队列的转换表示换行,优化思路记录当前层队列的长度。 代码: Python # Definition for a binary tree node. # class TreeNode(object): # de ...
分类:其他好文   时间:2020-06-09 16:56:07    阅读次数:49
100. 相同的树
class Solution(object): def isSameTree(self, p, q): """ :type p: TreeNode :type q: TreeNode :rtype: bool """ # 根节点值不同,树不同 if p.val != q.val: return Fa ...
分类:其他好文   时间:2020-06-08 14:46:48    阅读次数:57
【leetcode】1448. Count Good Nodes in Binary Tree
题目如下: Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X. Retur ...
分类:其他好文   时间:2020-06-04 10:33:57    阅读次数:77
二叉树展开成链表
先来一个前序遍历把所有结点存在一个列表中,然后遍历链表,把所有结点用右指针串起来 1 /** 2 * Definition for a binary tree node. 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * ...
分类:其他好文   时间:2020-05-30 22:05:09    阅读次数:83
剑指offer 二叉搜索树与双向链表
题目: 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。要求不能创建任何新的结点,只能调整树中结点指针的指向。 代码: 1 /* 2 struct TreeNode { 3 int val; 4 struct TreeNode *left; 5 struct TreeNode *righ ...
分类:其他好文   时间:2020-05-30 01:14:49    阅读次数:57
1958条   上一页 1 ... 16 17 18 19 20 ... 196 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!