代码随想录算法训练营第十八天|LeetCode 530,501,236

WSL2离线安装Ubuntu终极指南:绕过Microsoft Store慢速下载(附最新22.04 LTS离线包) 本文提供WSL2离线安装Ubuntu 22.04 LTS的完整指南,帮助开发者绕过Microsoft Store下载慢的问题。通过PowerShell命令配置环境、获取离线安装包并完成安装,同时包含初始配置、资源优化及常见问题解决方案,助您快速搭建高效的Linux开发环境。 阅读详情

目录

LeetCode  530.二叉搜索树的最小绝对差 

LeetCode 501.二叉搜索树中的众数 

LeetCode 236.二叉树的最近公共祖先


LeetCode  530.二叉搜索树的最小绝对差 

文章讲解:代码随想录

视频讲解:二叉搜索树中,需要掌握如何双指针遍历!| LeetCode:530.二叉搜索树的最小绝对差_哔哩哔哩_bilibili

力扣题目:LeetCode  530.二叉搜索树的最小绝对差 

 

代码如下(Java):递归

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {

    TreeNode pre;
    int result = Integer.MAX_VALUE;

    public int getMinimumDifference(TreeNode root) {

        if(root == null)    return 0;
        traversal(root);
        return result;
    }

    public void traversal(TreeNode root){

        if(root == null)    return;

        traversal(root.left);

        if(pre != null) result = Math.min(result, root.val - pre.val);

        pre = root;

        traversal(root.right);
    }
}

 代码如下(Java):迭代法

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {

    TreeNode pre;
    Stack<TreeNode> stack;

    public int getMinimumDifference(TreeNode root) {

        if(root == null)    return 0;

        stack = new Stack<>();

        TreeNode cur = root;

        int result = Integer.MAX_VALUE;

        while(cur != null || !stack.isEmpty()){

            if(cur != null){
                stack.push(cur);
                cur = cur.left;
            }else{
                cur = stack.pop();
                if(pre != null){
                    result = Math.min(result, cur.val - pre.val);
                }

                pre = cur;
                cur = cur.right;
            }
        }
        return result;
    }

}

LeetCode 501.二叉搜索树中的众数 

文章讲解:代码随想录

视频讲解:不仅双指针,还有代码技巧可以惊艳到你! | LeetCode:501.二叉搜索树中的众数_哔哩哔哩_bilibili

力扣题目:LeetCode 501.二叉搜索树中的众数 

代码如下(Java):中序遍历

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {

    ArrayList<Integer> resList;
    int maxCount;
    int count;
    TreeNode pre;

    public int[] findMode(TreeNode root) {

        resList = new ArrayList<>();

        maxCount = 0;
        count = 0;
        pre = null;

        findModel(root);

        int[] res = new int[resList.size()];

        for(int i = 0; i < resList.size(); i++){
            res[i] = resList.get(i);
        }

        return res;
    }

    public void findModel(TreeNode root){

        if(root == null)    return;

        findModel(root.left);

        int rootValue = root.val;

        if(pre == null || rootValue != pre.val){
            count = 1;
        }else{
            count++;
        }

        if(count > maxCount){
            resList.clear();
            resList.add(rootValue);
            maxCount = count;
        }else if(count == maxCount){
            resList.add(rootValue);
        }

        pre = root;

        findModel(root.right);
    }
}

LeetCode 236.二叉树的最近公共祖先

 文章讲解:代码随想录

视频讲解:自底向上查找,有点难度! | LeetCode:236. 二叉树的最近公共祖先_哔哩哔哩_bilibili

力扣题目:LeetCode 236.二叉树的最近公共祖先

 

 代码如下(Java):后序遍历

/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode(int x) { val = x; }
 * }
 */
class Solution {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        
        if(root == null || root == p || root == q)  return root;

        TreeNode left = lowestCommonAncestor(root.left, p, q);
        TreeNode right = lowestCommonAncestor(root.right, p, q);

        if(left == null && right == null)   return null;
        else if(left == null && right != null)  return right;
        else if(left != null && right == null)  return left;
        else    return root;
    }
}

BGP路由聚合:自动聚合和手动聚合 路由聚合是指将多条具体的路由合并为一条聚合路由,以减少路由表的条目数。这种技术通过只向对等体发送聚合后的路由,而不发送所有的具体路由,来减小路由表的规模。同时,被聚合的路由如果发生路由振荡,也不再对网络造成影响,从而提高了网络的稳定性。 阅读详情

相关推荐

Elsevier投稿别再踩坑了!手把手教你搞定LaTeX模板和所有附件(附避坑清单)

本文详细解析Elsevier投稿全流程中的关键环节,特别是LaTeX模板的使用和系统提交的常见问题。从必备文件准备到LaTeX模板适配,再到投稿系统操作指南,提供全面的避坑清单和实用技巧,帮助科研工作者高效完成投稿,避免因格式错误或文件遗漏导致的退稿风险。

weixin_30915275的博客 552

代码随想录算法训练营第十八天| leetcode 530、501、236

1.想要不断更新得到最小值,那么一开始res结果就要是最大值。2.为什么要判断pre不为空,不判断就会出错?因为pre初始化为空,在第一次迭代的时候还没有用cur跟新pre,所以需要判断。

hty123hty的博客 358

不用加速器!Google Earth Pro登录失败自救手册:从服务器连接到地图加载的完整排错流程

本文详细解析了Google Earth Pro登录失败的常见问题及解决方案,包括服务器连接失败、地图加载异常等。通过基础排查、内置修复工具使用和高级配置调整,帮助用户无需加速器即可解决启动问题、黑屏和转圈圈等困扰,提升软件使用体验。

weixin_29227425的博客 485

代码随想录算法训练营第十八天 | LeetCode669.修剪二叉搜索树、LeetCode108.将有序数组转换为二叉搜索树、LeetCode538.把二叉搜索树转换为累加树

题型关键理念二叉树的遍历前序、中序和后序;层序翻转二叉树前序、后序遍历对称二叉树遍历两棵树二叉树的最大深度、最小深度后序遍历完全二叉树的节点个数递归、通过2n-1优化平衡二叉树分别求出其左右子树的高度,然后如果差值小于等于1,则返回当前二叉树的高度,否则返回-1二叉树的所有路径前序遍历、回溯左叶子之和当遇到左叶子节点的时候,记录数值,然后通过递归求取左子树左叶子之和,和 右子树左叶子之和,相加便是整个树的左叶子之和找树左下角的值找深度最大的叶子节点路径总和。

zhuabazhuabahuo的博客 916

[ vulhub漏洞复现篇 ] Jetty WEB-INF 文件读取复现CVE-2021-34429

[ vulhub漏洞复现篇 ] Jetty WEB-INF 文件读取复现CVE-2021-34429 可以使用一些编码字符来制作URI,以访问WEB-INF目录的内容和/或绕过一些安全限制。默认合规模式允许带有包含 %u002e 段的 URI 的请求访问WEB-INF目录中的受保护资源。

qq_51577576的博客 3208

windows搭建IIS(FTP)

适用于参加网络系统管理的学生进行学习与参考

a1119619789的博客 280

代码随想录算法训练营|一刷总结与反思

一刷代码随想录正式结束,之前没有系统的学习过,甚至没有刷过力扣题,第一次刷的题采用的先看卡哥的视频然后再试着自己敲一遍代码的方式,中间还有一些题目看完之后写代码也仍然有不少问题,就跟着代码随想录的“参考代码”敲了一遍。断断续续花了两个月,终于成功的完成了代码随想录的一刷。总共刷的内容有:数组、链表、哈希表、字符串、双指针法、栈与队列、二叉树、回溯算法、贪心算法、动态规划、单调栈。

weixin_47748259的博客 1515

51单片机+DS18B20+数码管显示+超温提示+Proteus仿真

51单片机+DS18B20+数码管显示+超温提示+Proteus仿真 Proteus仿真 实例代码 #include <reg52.h> #define uchar unsigned char #define uint unsigned int sbit we1 = P3^0; sbit we2 = P3^1; sbit we3 = P3^2; sbit we4 = P3^3; sbit DS = P1^0; sbit D1 = P3^6; sbit D2 = P3^7; uch

perseverance51博客 1540

代码随想录算法训练营第二十九天|1005.K次取反后最大化的数组和,134. 加油站,135. 分发糖果

在一条环路上有 n 个加油站,其中第 i 个加油站有汽油 gas[i] 升。你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1 个加油站需要消耗汽油 cost[i] 升。给定两个整数数组 gas 和 cost ,如果你可以按顺序绕环路行驶一周,则返回出发时加油站的编号,否则返回 -1。你需要按照以下要求,给这些孩子分发糖果:每个孩子至少分配到 1 个糖果。给你一个整数数组 nums 和一个整数 k ,按以下方法修改该数组:选择某个下标 i 并将 nums[i] 替换为 -nums[i]。

weixin_47748259的博客 966

基于Simulink的四足机器人楼梯攀爬仿真模型

构建一个基于Simulink的四足机器人楼梯攀爬仿真模型,旨在模拟四足机器人在面对楼梯等障碍时的运动控制和稳定性调整。以下是一个详细的步骤指南,帮助你从零开始创建这样一个仿真模型。

xiaoheshang_123的博客 247

#systemverilog# 之 event region 和 timeslot 仿真调度(三)Verdi 辅助查看

通过今天的学习,我们知道:event region 是event sequence 的全集。我们打开了 event region feature 也就开启了event sequence 的功能。

那么菜的博客 1366

代码随想录第55期训练营第十八天|LeetCode530.二叉搜索树的最小绝对差、501.二叉搜索树中的众数、236.二叉树的最近公共祖先

打卡代码随想录算法训练营第55期第十八天(づ ̄3 ̄)づ╭❤~首先十分推荐学算法的同学可以先了解一下代码随想录,可以在B站。

tancxiaohei23的博客 228

精通 Android NDK/JNI:从入门到精通实战与面试精粹

在Android开发中,

郑伟强dev的专栏 144

代码随想录算法训练营第十八天|LeetCode530. 二叉搜索树的最小绝对差,LeetCode501. 二叉搜索树中的众数,LeetCode236. 二叉树的最近公共祖先

思路:定义一个变量保存差值,再定义一个节点用于保存前一个节点,然后函数依旧是中序遍历,然后挨个比较差值,保存最小的差值。

Liverpool0519的博客 719

深度学习工具包 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")

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

代码随想录算法训练营第三十四天|62.不同路径,63. 不同路径 II

一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 “Start” )。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为 “Finish”)。一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 “Start” )。确定dp数组(dp table)以及下标的含义:dp[i][j]表示从(0,0)出发,到(i, j) 有dp[i][j]条不同的路径。确定递推公式:dp[i][j] = dp[i - 1][j] + dp[i][j - 1]

weixin_47748259的博客 1763

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

代码随想录算法训练营第十八天|LeetCode530.二叉搜索树的最小绝对差、501.二叉搜索树中的众数、236.二叉树的最近公共祖先

打卡代码随想录算法训练营第49期第十八天ヾ(≧∇≦*)ゝ首先十分推荐学算法的同学可以先了解一下代码随想录,可以在B站。

tancxiaohei23的博客 382

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

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

18.代码随想录算法训练营第十八天|530. 二叉搜索树的最小绝对差,501. 二叉搜索树中的众数,236. 二叉树的最近公共祖先*

力扣算法

LXY999222的博客 939

代码随想录算法训练营第五十二天|84.柱状图中最大的矩形,完结撒花✿✿ヽ(°▽°)ノ✿

给定一个循环数组 nums ( nums[nums.length - 1] 的下一个元素是 nums[0] ),返回 nums 中每个元素的 下一个更大元素。数字 x 的 下一个更大的元素 是按数组遍历顺序,这个数字之后的第一个比它更大的数,这意味着你应该循环地搜索它的下一个更大的数。如果不存在,则输出 -1。本题和42. 接雨水 (opens new window),是遥相呼应的两道题,接雨水是求外,柱状图中最大的矩形是求内。

weixin_47748259的博客 1227

代码随想录算法训练营第十八天|LeetCode530.二叉搜索树的最小绝对差、LeetCode501.二叉搜索树中的众数、LeetCode236. 二叉树的最近公共祖先

LeetCode530.二叉搜索树的最小绝对差文章讲解:代码随想录视频讲解:LeetCode:530.二叉搜索树的最小绝对差_哔哩哔哩_bilibiliLeetCode501.二叉搜索树中的众数文章讲解:代码随想录视频讲解:LeetCode:501.二叉搜索树中的众数_哔哩哔哩_bilibiliLeetCode236. 二叉树的最近公共祖先文章讲解:代码随想录视频讲解:LeetCode:236. 二叉树的最近公共祖先_哔哩哔哩_bilibili。

python1_1的博客 322

代码随想录算法训练营第二十三天|39. 组合总和,40.组合总和II,131.分割回文串

给你一个 无重复元素 的整数数组 candidates 和一个目标整数 target ,找出 candidates 中可以使数字和为目标数 target 的 所有 不同组合 ,并以列表形式返回。如果至少一个数字的被选数量不同,则两种组合是不同的。给定一个候选人编号的集合 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。candidates 中的每个数字在每个组合中只能使用 一次。核心问题是去重,而且是树层去重而不是树枝去重;

weixin_47748259的博客 1317

代码随想录算法训练营第十八天 | 513.找树左下角的值、112. 路径总和、113. 路径总和ii

链接: 513.找树左下角的值 链接: 112. 路径总和,和 113. 路径总和ii 链接: 从中序与后序遍历序列构造二叉树 513.找树左下角的值:层序遍历,输出最后一行的最左边的值。自己亲手写代码之后发现,有个问题就是,你怎么知道此时就是最后一层呢?另一种方法是递归法,采用后序遍历,递归处理逻辑是当中间节点的左叶子节点的子节点都为空的时候返回该左叶子节点的值。自己亲手写代码之后发现编译错误,缺少return语句。 112.路径总和和 113.路径总和ii:使用递归法用三部曲思考,第一返回类型和参数,

qq_45163431的博客 1248

代码随想录算法训练营第十八天 | 530.二叉搜索树的最小绝对差、501.二叉搜索树中的众数、236. 二叉树的最近公共祖先

代码随想录算法训练营第十八天 | 530.二叉搜索树的最小绝对差、501.二叉搜索树中的众数、236. 二叉树的最近公共祖先

2301_81109252的博客 775

代码随想录算法训练营第十八天|LeetCode513、LeetCode112、LeetCode113、LeetCode106、LeetCode105

代码随想录算法训练营第十八天|LeetCode513、LeetCode112、LeetCode113、LeetCode106、LeetCode105

qq_42498113的博客 305

【代码随想录数据结构刷题记录】

代码随想录算法训练营

ThreeStones1029的博客 935

代码随想录算法训练营第十八天 | 前中后序构造二叉树

递归求深度的写法,我们在110.平衡二叉树 (opens new window)中详细的分析了深度应该怎么求,高度应该怎么求。递归中其实隐藏了回溯,在257. 二叉树的所有路径 (opens new window)中讲解了究竟哪里使用了回溯,哪里隐藏了回溯。层次遍历,在二叉树:层序遍历登场!深度讲解了二叉树层次遍历。所以本题涉及到的点,我们之前都讲解过,这些知识点需要同学们灵活运用,这样就举一反三了。112. 路径总和。

Fight___的博客 998

@[TOC](代码随想录算法训练营第十八天|Leetcode513 找树左下角的值、Leetcode112 路径总和、Leetcode106 从中序与后序遍历序列构造二叉树

如果存在,返回 true;否则,返回 false。我们需要得到的是左下角的值,显然左下角的值不管是上一层结点的左孩子或者右孩子,都一定会是叶子结点,同时我们需要对其深度进行判断,因此左下角的值一定处于二叉树的最后一层,即深度最大;输入:root = [5,4,8,11,null,13,4,7,2,null,null,null,1], targetSum = 22。不难看出,通过前序遍历或者后序遍历能很快知道根结点的值,因为根结点值为前序遍历的第一个元素,为后序遍历遍历的最后一个元素,因此。

Demok123的博客 1065
上一篇: 代码随想录算法训练营第十七天|LeetCode 654,617,700,98
下一篇: 代码随想录算法训练营第十九天|LeetCode 235,701,450
iwtup
博客等级 码龄8年 2粉丝 54原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值