Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only n...
分类:
其他好文 时间:
2015-07-30 12:59:04
阅读次数:
115
题目:
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
题解:将一个有序链表转成二叉排序树,如果是一棵相对平衡的排序树,应该是这样的,链表中间那个节点为树的根节点,根节点的左子树节点应该是根节点左边那部分的中间节点,根节点的...
分类:
编程语言 时间:
2015-07-30 09:33:16
阅读次数:
150
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x...
分类:
其他好文 时间:
2015-07-30 09:29:33
阅读次数:
195
class Solution {public: int numTrees(int n) { if(n<=2) return n; int i=1; n --; int sum=0; while(i<n){ ...
分类:
其他好文 时间:
2015-07-30 09:23:43
阅读次数:
100
算法导论:10.4-3给定一个 n 二叉树结点,写一个 O(n) 非递归处理时间,树中的每个节点keyword出口。堆栈可以用作辅助数据结构。堆栈实现参考这里。#ifndef _BINARY_TREE_USE_STACK_H_#define _BINARY_TREE_USE_STACK_H_/***...
分类:
其他好文 时间:
2015-07-30 08:16:44
阅读次数:
158
Givenn, generate all structurally uniqueBST's(binary search trees) that store values 1...n.For example,Givenn= 3, your program should return all 5 uni...
分类:
其他好文 时间:
2015-07-30 01:58:55
阅读次数:
171
华电北风吹
天津大学认知计算与应用重点实验室
完成日期:2015/7/29Double-base palindromes
Problem 36
The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.Find the sum of all numbers, less than one milli...
分类:
其他好文 时间:
2015-07-30 00:50:29
阅读次数:
139
Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1.....
分类:
其他好文 时间:
2015-07-30 00:26:06
阅读次数:
182
题目:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as00000010100101000001111010011100), retu...
分类:
其他好文 时间:
2015-07-30 00:18:26
阅读次数:
203
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.
According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined
betw...
分类:
其他好文 时间:
2015-07-29 23:04:12
阅读次数:
132