给定一个二叉搜索树的两个节点,找出他们的最近公共祖先,如, _______6______ / \ ___2__ ___8__ / \ / \ 0 4 7 ...
分类:
其他好文 时间:
2016-01-24 23:48:59
阅读次数:
143
二叉树的中序遍历,即左子树,根, 右子树 1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right;...
分类:
其他好文 时间:
2016-01-24 22:12:43
阅读次数:
123
题目:Givenabinarytree,flattenittoalinkedlistin-place.算法思路:其实该题目就是二叉树前序遍历的变形我代码沿用leetcode144.BinaryTreePreorderTraversal代码:classSolution(object):
defpreorderTraversal(self,root):
"""
:typeroot:TreeNode
:rtype:List[int]
"""
ifro..
分类:
编程语言 时间:
2016-01-24 19:55:41
阅读次数:
233
问题描写叙述:Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”. 解决方式:class Solution {publ...
分类:
其他好文 时间:
2016-01-24 19:36:46
阅读次数:
114
题目:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.提示:题目要求通过一颗...
分类:
其他好文 时间:
2016-01-24 15:39:31
阅读次数:
265
在此之前回顾前序遍历和中序遍历:
1,前序遍历:
基本规则,总是先访问根节点在左节点,在右节点
递归解法:
class Solution {
public:
vector result;
vector preorderTraversal(TreeNode* root) {
if(root){
result.push_back(root...
分类:
其他好文 时间:
2016-01-24 11:42:41
阅读次数:
131
public class Solution { public boolean search(int[] nums, int target) { int len = nums.length; if(len == 0) return false; int ...
分类:
其他好文 时间:
2016-01-24 07:02:47
阅读次数:
169
二叉树是一种数据结构,每个节点都有两个子节点。二叉树的遍历有三种方式,先序遍历是 根节点,左子树,右子树;中序遍历是 左子树,根节点,右子树;后序遍历是 左子树,右子树,根节点;java实现: 1 package com.gh.Binary; 2 3 /** 4 * 二叉树的实现 5 * 6...
分类:
编程语言 时间:
2016-01-24 00:22:59
阅读次数:
173
题目:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1反转二叉树,左右儿子值交换代码:/*** Definition for ...
分类:
其他好文 时间:
2016-01-23 23:12:29
阅读次数:
174
Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing all 1’s and return its area.For example, given the follow...
分类:
其他好文 时间:
2016-01-23 21:15:27
阅读次数:
169