码迷,mamicode.com
首页 >  
搜索关键字:binary trees    ( 12390个结果)
leetcode[96] Binary Tree Inorder Traversal
给定树根root。实现中序遍历,也就是左根右。用递归的话,很简单,左边的返回值加上root的再加上右边的就行。我自己写的有点挫:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *le...
分类:其他好文   时间:2014-11-25 01:34:34    阅读次数:129
leetcode Unique Binary Search Trees II
和上一题Unique Binary Search Trees一样,这里是要记录所有的可能。存在树里面。这题还是有点难的,我拿了笔写了前几个,推敲了一下,发现如果和上一题一样,存前面的值计算后面的的话会非常复杂,且可能涉及到给一颗数的所有节点加某个值。最终还是放弃用这个方法。可行的二叉查找树的数量是相...
分类:其他好文   时间:2014-11-25 00:15:15    阅读次数:275
【Leetcode】【Easy】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...
分类:其他好文   时间:2014-11-25 00:02:20    阅读次数:428
[leetcode] 16. Add Binary
这个题目相对有点奇怪,题目如下: Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 可能是我思路的问题吧,我之前是在考虑先将st...
分类:其他好文   时间:2014-11-25 00:01:55    阅读次数:180
【LeetCode】Convert Sorted List to Binary Search Tree 解题报告
【题目】 Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. 【解析】 分治:用快慢指针找到链表的中点,作为树的root,然后二分——中点之前的链表和中点之后的链表分别再构造二叉平衡树。 /** * Defin...
分类:其他好文   时间:2014-11-24 22:39:00    阅读次数:218
leetcode-Binary Tree Level Order Traversal 二叉树层序遍历
leetcode-Binary Tree Level Order Traversal 二叉树层序遍历 #include #include using namespace std; typedef struct BiTree { int val; struct BiTree *lchild; struct BiTree *rchild; }BiTree; void main(...
分类:其他好文   时间:2014-11-24 22:35:13    阅读次数:202
[LeetCode]Binary Tree Level Order Traversal
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,#,#,15,7}, 3 / 9 20 ...
分类:其他好文   时间:2014-11-24 22:33:13    阅读次数:272
[LeetCode]Binary Tree Zigzag Level Order Traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary ...
分类:其他好文   时间:2014-11-24 22:31:45    阅读次数:196
求二叉树第K层的叶子节点的个数(假设根节点是第一层)
算法思想:采用队列结构按层次遍历,遍历K层时记录叶子的个数   int LeafKlevel(BiTree bt, int k){ //求二叉树bt的第k(k >1)层上叶子的节点个数 if(bt == NULL || k < 1) return 0; BiTree p=bt,Q[]; //Q是队列,元素是二叉树节点的指针 int...
分类:其他好文   时间:2014-11-24 19:19:09    阅读次数:393
linux基础知识 【转】
linux目录架构/ 根目录/bin 常用的命令 binary file 的目錄/boot 存放系统启动时必须读取的档案,包括核心 (kernel) 在内/boot/grub/menu.lst GRUB设置/boot/vmlinuz 内核/boot/initrd 核心解壓縮所需 RAM Disk/d...
分类:系统相关   时间:2014-11-24 18:57:48    阅读次数:281
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!