我的代码游记

标签 · 二叉树

首页

关于

归档

loading..
LeetCodeEasy递归二叉树

226.Invert Binary Tree(Easy)

Invert a binary tree.反转二叉树 *  基本上二叉树的玩意儿用递归都能做* For example to My Solution(Java) Version 1  Time: 1ms:  简单地递归然后调换左右子树 /**  * Definition for a binary tree node.  * public class TreeNode {  *     int val;  *     TreeNode left;  *     TreeNode right;  *     TreeNode(int x) { val = x; }  * }  */ public class Solution {     public T..

更多
LeetCodeEasy二叉树队列

102.Binary Tree Level Order Traversal(Easy)

Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level).给定一个二叉树,返回他的水平层序遍历(从左到右,一层再一层) *  一个对队列的巧妙应用* For example Given binary tree [3,9,20,null,null,15,7].**  3 /   9   20     /      15   7**return its level order traversal as:[ [3], [9,20], [15,7] ] My Solution(Java) Version 1 Time: 3ms:  ..

更多
计数LeetCodeMedium递归二叉树

222.Count Complete Tree Nodes(Medium)

Given a complete binary tree, count the number of nodes.给定一个完全二叉树,计算其节点数 **Definition of a complete binary tree from Wikipedia:**In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h. *  难度在于其如何优..

更多
LeetCodeEasy二叉树一行实现

100.Same Tree(Easy)

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.给定两个二叉树,写一个函数检查它们是否相同。如果两个二叉树相同结点的值相同,则认为这两个二叉树相同。 My Solution(Java) Version 1 Time: 0ms:  并没有什么大坑,只是简单地遍历两个二叉树并判断结点的值是否相等就ok了,测试样例似乎也没有走极端,用递归也没有超时,确实是Easy题 /** * Definiti..

更多