二叉树中两个节点的最低公共祖先

二叉树中查找两个节点的最低公共祖先 这是一道企业面试中,经常会被问到的面试题目。 在网上看到一些此题的实现,其中有两种方法是比较适合编程的。本项目的源代码,请点击这里下载。 方法一:   此方法是根据二叉树的DFS查找并标记祖先,根据递归出栈的原理,找到公共祖先。   其主要代码如下: 阅读详情

求二叉树树中的两个节点的最低公共祖先是个有趣的问题,涉及到对递归的理解。

可以参考博客:https://www.cnblogs.com/felixfang/p/3828915.html

转自:http://gaotong1991.iteye.com/blog/2042770

 

方法一

下面是一个简单的复杂度为 O(n) 的算法,解决LCA问题
1) 找到从根到n1的路径,并存储在一个向量或数组中。
2)找到从根到n2的路径,并存储在一个向量或数组中。
3) 遍历这两条路径,直到遇到一个不同的节点,则前面的那个即为最低公共祖先.

需要log(n)的辅助空间。

// O(n) 解决 LCA
#include <iostream>
#include <vector>
using namespace std;

//二叉树节点
struct Node
{
    int key;
    struct Node *left, *right;
};
//公用函数,生成一个节点
Node * newNode(int k)
{
    Node *temp = new Node;
    temp->key = k;
    temp->left = temp->right = NULL;
    return temp;
}
//找到从root到 节点值为key的路径,存储在path中。没有的话返回-1
bool findpath(Node * root,vector<int> &path,int key){
    if(root == NULL) return false;
    path.push_back(root->key);
    if(root->key == key) return true;
    //左子树或右子树 是否找到,找到的话当前节点就在路径中了
    bool find =  ( findpath(root->left, path, key) || findpath(root->right,path ,key) );
    if(find) return true;
    //该节点下未找到就弹出
    path.pop_back();
    return false;
}
 
int findLCA(Node * root,int key1,int key2){
    vector<int> path1,path2;
    bool find1 = findpath(root, path1, key1);
    bool find2 = findpath(root, path2, key2);
    if(find1 && find2){
        int ans ;
        for(int i=0; i<path1.size(); i++){
            if(path1[i] != path2[i]){
                break;
            }else
                ans = path1[i];
        }
        return ans;
    }
    return -1;
}
// Driver program to test above functions
int main()
{
    // 按照上面的图来创创建树
    Node * root = newNode(1);
    root->left = newNode(2);
    root->right = newNode(3);
    root->left->left = newNode(4);
    root->left->right = newNode(5);
    root->right->left = newNode(6);
    root->right->right = newNode(7);
    cout << "LCA(4, 5) = " << findLCA(root, 4, 5);
    cout << "\nLCA(4, 6) = " << findLCA(root, 4, 6);
    cout << "\nLCA(3, 4) = " << findLCA(root, 3, 4);
    cout << "\nLCA(2, 4) = " << findLCA(root, 2, 4);
    return 0;
}
 

 

第二种方法(只遍历一次)

上面的方法虽然是O(n),但是操作依然繁琐了一点,并且需要额外的空间来存储路径。其实可以只遍历一次,利用递归的巧妙之处。学好二叉树,其实就是学好递归。

从root开始遍历,如果n1和n2中的任一个和root匹配,那么root就是LCA。 如果都不匹配,则分别递归左、右子树,如果有一个 key(n1或n2)出现在左子树,并且另一个key(n1或n2)出现在右子树,则root就是LCA.  如果两个key都出现在左子树,则说明LCA在左子树中,否则在右子树。

/* 只用一次遍历解决LCA */
#include <iostream>
using namespace std;
struct Node
{
    struct Node *left, *right;
    int key;
};
Node* newNode(int key)
{
    Node *temp = new Node;
    temp->key = key;
    temp->left = temp->right = NULL;
    return temp;
}

// 返回n1和n2的 LCA的指针
// 假设n1和n2都出现在树中
struct Node *findLCA(struct Node* root, int n1, int n2)
{
    if (root == NULL) return NULL;
    // 只要n1 或 n2 的任一个匹配即可
    //  (注意:如果 一个节点是另一个祖先,则返回的是祖先节点。因为递归是要返回到祖先的 )
    if (root->key == n1 || root->key == n2)
        return root;
    // 分别在左右子树查找
    Node *left_lca  = findLCA(root->left, n1, n2);
    Node *right_lca = findLCA(root->right, n1, n2);
    // 如果都返回非空指针 Non-NULL, 则说明两个节点分别出现了在两个子树中,则当前节点肯定为LCA
    if (left_lca && right_lca)  return root;
    // 如果一个为空,在说明LCA在另一个子树
    return (left_lca != NULL)? left_lca: right_lca;
}
//测试
int main()
{
    // 构造上面图中的树
    Node * root = newNode(1);
    root->left = newNode(2);
    root->right = newNode(3);
    root->left->left = newNode(4);
    root->left->right = newNode(5);
    root->right->left = newNode(6);
    root->right->right = newNode(7);
    cout << "LCA(4, 5) = " << findLCA(root, 4, 5)->key;
    cout << "\nLCA(4, 6) = " << findLCA(root, 4, 6)->key;
    cout << "\nLCA(3, 4) = " << findLCA(root, 3, 4)->key;
    cout << "\nLCA(2, 4) = " << findLCA(root, 2, 4)->key;
    return 0;
}
 

 

Zynq 双核AMP 通信 4、配置离线编译(这里不讲),配置linux的内核地址空间(0x4000_0000改为0x2000_0000),以及单核启动。CPU1设置为0x2000_0000~0x3FFF_FFFF(也可以小于0x3FFF_FFFF)如果禁用CPU1的L2 cache,在CPU1的bsp里面添加编译时候所需要的宏。3、配置工程,将vivado产生的.xsa文件复制到amp_com项目目录下。9、使用petalinux-package --boot 打包。一、vivado工程。5、编译u-boot。 阅读详情

相关推荐

微型纵向加密在新能源场站中的实战部署与运维避坑指南

本文详细解析了微型纵向加密在新能源场站中的实战部署与运维技巧。通过国密算法SM4实现数据加密,确保新能源场站通信安全,同时提供非侵入式部署方案和运维避坑指南,帮助提升网络稳定性和运维效率。

weixin_30505225的博客 598

二叉树的最小公共祖先问题

转自:http://blog.youkuaiyun.com/wuyilun2013/article/details/47325401 一,二叉排序数树 具体思路如下: 1 如果两个节点都比当前节点小, 那公共祖先必然是当前节点的左子树上, 所以递归左子树; 2 如果两个节点都比当前节点大, 那么同上, 递归右子树; 3 如果两个节点有一个为当前节点, 则当前节点为公共节点; 如果两个节点分别

程序狗的成长之路 1461

手把手教你学simulink(12.10)--设计和仿真一个用于控制飞机纵向运动(高度和速度)的多变量控制系统

飞机的纵向运动控制是航空工程中的一个重要问题,涉及飞机的高度和速度的精确控制。多变量控制系统可以同时控制多个飞行参数,确保飞机在最佳条件下运行。Simulink提供了一个强大的平台,用于建模、仿真和分析动态系统,非常适合设计和测试多变量控制系统。通过本项目的实施,我们成功设计和仿真了一个用于控制飞机纵向运动(高度和速度)的多变量控制系统。该项目展示了从系统建模、控制器设计、仿真验证到结果分析的完整流程,为多变量控制系统的设计提供了有价值的参考。

MHD0815的博客 598

二叉树两个节点的最小公共祖先节点(LeetCode-236)

1、题目描述 给定一棵二叉树和二叉树中的两个节点,找出这两个节点的公共祖先节点。例如: 给定两个节点p = 5, q = 4,那么p和q的最小的公共祖先节点为5。 2、解题思路 可以分别使用两个数组来保存从根节点到给定的两个节点的路径值,然后再从路径中找出最后一个相...

蓬莱道人的博客 2438

Rancher入门到精通 - Nginx Ingress 配置指南

Rancher 是一个开源的容器管理平台,它提供了一套完整且易于使用的工具来部署、管理和扩展容器化应用。而 Nginx Ingress 则是一个常用的开源 Ingress 控制器,用于将外部请求流量导入到 Kubernetes 集群中的服务。在开始之前,请确保您已经正确安装了 Rancher 平台和 Nginx Ingress 控制器。

TechInk的博客 1312

conda install出现CondaValueError: Malformed version string invalid character(s)解决方案

本文主要介绍了conda install出现Solving environment:failed、CondaValueError: Malformed version string invalid character(s),希望能对新手有所帮助。 文章目录 1. 问题描述 2. 解决方案 2.1 步骤一 2.2 步骤二 2.3 步骤三

weixin_43178406的博客 6万+

树中两个结点的最低公共祖先

给出一个二叉树,输入两个树节点,求它们的最低公共祖先。 一个树节点的祖先节点包括它本身。 注意: 输入的二叉树不为空; 输入的两个节点一定不为空,且是二叉树中的节点; 样例 二叉树[8, 12, 2, null, null, 6, 4, null, null, null, null]如下图所示: 8 / \ 12 2 / \ 6 4 如果输入的树节点...

weixin_44356316的博客 310

Qt 5.14安装(配置MSVC 2017)

本文主要介绍Qt MSVC的安装,VS2017.

ifeng12358的博客 3711

二叉树系列 - 求两节点的最低公共祖先,例 剑指Offer 50

前言 本篇是对二叉树系列中求最低公共祖先类题目的讨论。 题目 对于给定二叉树,输入两个树节点,求它们的最低公共祖先。 思考:这其实并不单单是一道题目,解题的过程中,要先弄清楚这棵二叉树有没有一些特殊的性质,这些特殊性质可以便于我们使用最优的方式解题。 传统二叉树的遍历,必须从跟节点开始,因此,思路肯定是从根节点找这两个节点了。但是,如果节点带有指向父节点的指针呢?这种情况下,...

weixin_30687051的博客 412

微信支付接口「系统繁忙 SYSTEM_ERROR」/「文件不存在」报错分析与解决方案 接口开发实现SDK

微信支付的“平台证书模式”只有5年的有效期,过期后微信支付将不再签发新的平台证书,转而要求开发者使用“微信支付公钥”来处理敏感信息加密及回调签名验证。然而,由于以下几点原因,许多开发者在调用 获取平台证书。尽管微信支付在技术迭代上有其必要性,但报错设计过于不友好。诸如“系统繁忙”这样的提示很难直接关联到平台证书失效或公钥切换问题。这样的信息表达,开发者不仅看不懂,还需要花费大量时间分析排查,非常影响效率。

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 788

GoAnywhere MFT 身份验证绕过漏洞(CVE-2024-0204)

GoAnywhere MFT 身份验证绕过漏洞(CVE-2024-0204)

weixin_43567873的博客 387

【算法题】二叉树寻找最小公共祖先

输入:4,5。输出:2。 输入:4,9。输出:1. 从root开始遍历,如果n1和n2中的任一个和root匹配,那么root就是LCA。 如果都不匹配,则分别递归左、右子树,如果有一个 key(n1或n2)出现在左子树,并且另一个key(n1或n2)出现在右子树,则root就是LCA. 如果两个key都出现在左子树,则说明LCA在左子树中,否则在右子树。 public class Test16 { static class Node { int val; ...

qq_33300570的博客 926

华为OD机试双机位C卷-虚拟文件系统(C/C++/Py/Java/Js/Go)

华为OD机试(机考)双机位C卷 【虚拟文件系统】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【虚拟文件系统】。

qq_45776114的博客 479

二叉树最小公共祖先Java,求二叉树中两个节点的最低公共祖先节点

直接贴代码,关于求二叉树中两个节点的最低公共祖先节点#include "stdafx.h"#include #include using namespace std;//定义二叉树的节点struct BinaryTreeNode{char m_nvalue;BinaryTreeNode * m_pleft;BinaryTreeNode * m_pright;};//创建值为value的节点Bina...

weixin_39982580的博客 180

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

二叉树中两节点的最低公共祖先

二叉树中两节点的最低公共祖先 要求如下: 给定一个头节点head 和另外两个节点 a b 返回 a 和 b 的最低公共祖先 代码和思路如下: package beginner.tree; /** * 给定一个头节点head * 和另外两个节点 a b * 返回 a 和 b 的最低公共祖先 * * @Auther: 苏察哈尔丶灿 * @Date: 2020/9/28 14:10 * @Slogan: 我自横刀向天笑,笑完我就去睡觉。 */ public class LowParentNo

weixin_41826641的博客 320

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

返回二叉树中两个节点的最低公共祖先

二叉树递归套路求解两个节点的最低公共祖先

明朗晨光的专栏 618

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

二叉树中寻找共同节点的最低公共祖先节点

线性时间复杂度和 O(1)空间复杂度求二叉树中两个节点的最低公共祖先节点。

lizhihaoweiwei的专栏 1453

寻找二叉树的最低公共祖先节点

寻找二叉树的最低公共祖先节点

m0_73530538的博客 273

求二叉树中两个节点的最低公共祖先节点

本篇博客接着写二叉树的面试题中:二叉树面试题(一)   二叉树面试题(二)   求树中两个节点的最低公共祖先节点 这个题可能有几种不同的条件,那这样就是不同的问题 (1) 树是二叉树,且是二叉搜索树。 思路:如果是二叉搜索树,二叉搜索树是排序过的,位于左子树的节点都比父节点小,位于右子树的节点都比父节点大。我们只需要从树的根节点开始和两个输入的节点进行比较。如果当前节点的值比两个节点的值都

菜鸟成长记 5181

求二叉树的两个节点的最低公共祖先节点

这是一道很经典的问题,《剑指Offer》上给出的解法是先找到从根节点到这两个节点的简单路径,这两条简单路径的最后公共节点就是这两个节点的最低公共祖先节点。本文给出的解法不必找到从根节点到这两个节点的简单路径,而且还可以很容易地判断这两个节点是否在这棵二叉树上。 结合代码讲解,代码如下: /*求二叉树的两个节点的最低公共祖先节点*/ int FindLowestCommonAncestor(P

tgyd2014的博客 654

寻找二叉树中两个节点的最低公共祖先

给定一棵二叉树的根节点和两个节点p和q,要求找到这两个节点的最低公共祖先。通过递归的方法,可以非常高效地在二叉树中寻找两个节点的最低公共祖先。这种方法利用了二叉树的结构特点,避免了不必要的计算,非常适合处理常见的二叉树结构问题。

抟土成人祖,炼石补青天。眼中览银河,手可摘星辰。 823

如何找出一个二叉树中任意两个节点的最低公共祖先?

本文将介绍如何找出一个二叉树中任意两个节点的最低公共祖先。本文将介绍如何找出一个二叉树中任意两个节点的最低公共祖先,文中使用了二叉树递归的套路解决了这道题,另外还可以使用Map来暴力递归方式实现,这里接不再介绍了,有兴趣的小伙伴可以自己试试~

m0_71777195的博客 273

二叉树专题-求两个节点的最低公共祖先

根据上面情况,我们定义每次递归需要的结果,是否找到a节点,是否找到b节点,是否找到最低公共祖先。1.和给出的头节点有关,左树找出一个节点,右树找出另外一个节点。给出二叉树中的两个节点,查找其最低的公共祖先。解题思路,递归时,就要把可能的情况列出来。2.左树找出两个节点,3.在右树找出两个节点。

SP_1024的博客 366
上一篇: python面向对象的特性
下一篇: 生成括号-回溯的应用
runner668
博客等级 码龄11年 161粉丝 137原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值