leetcode 1519. Number of Nodes in the Sub-Tree With the Same Label(子树中相同Label的节点个数)

汽车诊断服务(UDS——0x11服务解析) ECU复位服务(0x11)详解:该服务支持硬件/钥匙开关/软件三种复位类型(0x01-0x03),复位前需发送肯定响应。请求格式为11+子功能,响应含51+子功能。典型应用需配合安全访问流程,测试时需监控CAN总线通信及DTC状态。复位后ECU将返回默认会话,期间不处理任何诊断请求。服务在编程会话且安全解锁后执行,硬复位会初始化存储数据。 阅读详情

在这里插入图片描述
不一定是二叉树,共有n个节点,edges代表了互相连接的顶点形成的边,
每个节点有一个label, label是小写英文字母。
第 i 个字母表示第 i 个节点的标签。

问在同一子树中,相同标签的节点个数。
需要返回一个长度为n的数组,ans[i] 处的值表示在以节点i为根的子树中,和节点i 的标签相同的节点个数。

思路:

要找子树的每个节点的话,首先想到DFS。

现在的问题是怎么记录下子节点的label, 和这个label出现的次数。
可以用HashMap来记录,当然由于字母只有26个,可以用长度为26的数组记录下每个label出现的次数。

子节点遍历完之后,会得到一些字母上对应的次数>0了,
这个子树的根节点,要选出它的label对应的次数,放在ans[i]里面。

当然,首先还是要构建无向图,
然后要记录下每个节点是否已经被访问过,可以用visited数组记录,
由于没有环的存在,也可以只看child是不是上一节点即可。

class Solution {
    List<Integer>[] graph;
    int[] ans;

    public int[] countSubTrees(int n, int[][] edges, String labels) {
        graph = new ArrayList[n];
        ans = new int[n];
        HashSet<Character> chLabels = new HashSet<>();

        for(int i = 0; i < n; i++) graph[i] = new ArrayList<>();

        for(int[] edge : edges) {
            graph[edge[0]].add(edge[1]);
            graph[edge[1]].add(edge[0]);
        }

        chLabels.add(labels.charAt(0));
        dfs(-1, 0, labels);

        return ans;
    }

    int[] dfs(int pre, int node, String labels) {
        int[] tmp = new int[26];
        
        for(int child : graph[node]) {
            if(pre == child) continue;
            int[] res = dfs(node, child,labels);
            for(int i = 0; i < 26; i++) tmp[i] += res[i];
        }
        ans[node] = ++tmp[labels.charAt(node)-'a'];
        return tmp;
    }
}
Python与ArcGIS系列(二)获取地图文档 在ArcPy中,要引用当前的地图文档(Map Document),可以使用 mapping 模块中的 MapDocument 类。值得注意的是,在arcgis内部python窗口运行该代码才能访问已加载进arcgis的文档,如果通过其他idle则无法访问。要引用磁盘上的地图文档并对其进行一些设置,同样可以使用ArcPy中的 mapping 模块和 MapDocument 类。对于我们平常的工作,接触最多的就是图层数据处理,获取图层后就可以方便地进行下一步处理。 阅读详情

相关推荐

论文阅读:Visual Relationship Detection with Language Priors

Visual Relationship Detection with Language Priors(ECCV2016) 文章   尽管大多数的relationship并不常见,但是它们的object和predicate却更频繁地独立出现。paper用这个insight分别独立训练训练object和predicate的模型,然后再进行组合来预测relationship。Visual relatio...

Kivee的博客 2877

LeetCode 1519. Number of Nodes in the Sub-Tree With the Same Label

given a tree, containing n nodes and n-1 edges. the root is node 0 and each node has a label(character), that means The node with the number i has the label labels[i]. The edges array is given on the form edges[i] = [ai, bi], which means there is an edge b

Tech in Pieces 572

Diffusion Model进阶解析:从SDE到概率流ODE的连续化生成建模

本文深入解析了Diffusion Model的连续化生成建模,从离散DDPM和SGM模型引入,阐述了采用随机微分方程(SDE)统一视角的必要性与优势。文章详细拆解了SDE的构成,揭示了其如何统一描述扩散过程,并重点介绍了逆向SDE与确定性的概率流ODE,后者为高效、确定的图像生成提供了理论基础。最后,文章对比了朗之万动力学、数值SDE求解器和数值ODE求解器(如DPM-Solver)等主流采样方法的实战应用与选择策略。

weixin_29099217的博客 437

[leetcode] 1519. Number of Nodes in the Sub-Tree With the Same Label

Description Given a tree (i.e. a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. The root of the tree is the node 0, and each node of the tree has a label which is a lower-case charact

Learning from the mistakes 343

STM32F103C8T6最小系统板GPIO配置避坑指南:从原理图到流水灯一次成功

本文详细介绍了STM32F103C8T6最小系统板GPIO配置的实战指南,从硬件准备到流水灯实现,涵盖了九大关键步骤。特别针对新手常见问题,如GPIO配置、开发环境搭建和程序下载调试,提供了详细的解决方案和避坑技巧,帮助开发者快速掌握STM32开发基础。

weixin_33756596的博客 339

【DMA】认识 DMA 及其工作流程(与传统CPU存取方式的区别)

【DMA】认识 DMA 及其工作流程(与传统CPU存取方式的区别)

challenglistic的博客 5万+

【Leetcode】1519. Number of Nodes in the Sub-Tree With the Same Label

每个顶点有个字符标记,以字符串。

数学、算法爱好者的博客 456

【OpenClaw从入门到精通】第37篇:教育“龙虾”进化论——从答疑助教到全流程智能教学系统(2026实测版)

2026年,教育AI已从被动答疑的L1级进化至主动教学的L4级,清华开源的OpenMAIC平台更是打破传统慕课局限,实现互动式AI课堂。本文基于天津工业大学、西北农林科技大学等高校的真实应用案例,结合腾讯云、天翼云的实操指南,详解OpenClaw在教育场景的四层进化路径。核心内容包括:L1-L4级教育自动化架构解析、清华OpenMAIC L4级AI课堂深度拆解、从零搭建智能答疑(QQ群机器人)+作业批改+学情分析全流程系统,以及高校网络安全合规部署方案。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 774

Leetcode 1519. Number of Nodes in the Sub-Tree With the Same Label DFS 图遍历

class Solution { private: vector<vector<int>> cnt; void dfs(int tmp, int par, vector<vector<int>> &graph){ for(auto u: graph[tmp]){ if(par!=u){ dfs(u, tmp, graph); for

Xurui_Luo的博客 306

uniapp [全端兼容] - 详细实现集成接入萤石云摄像头监控示例代码,页面单个或多个九宫格监控画面同时监控播放推流(视频控制方向上下左右移动/调节音量声音/全屏/截屏录制/回放/对讲/切换清晰度)

uni-app,h5移动端网页,小程序,安卓,苹果ios,app,nvue,EZVIZ萤石,uniapp萤石云摄像头监控,uniApp项目集成萤石云详细示例代码,Uniapp中使用萤石云播放视频,使用萤石云播放视频,萤石云实现多窗口监控,展示多个监控画面同时播放,ezuikit.js,云台控制左右移动,莹石摄像头直播视频,萤石视频回放,摄像头黑屏不显示,加载慢报错出错,多个摄像头宫格布局,niapp萤石云视频监控对接,实现海康萤石直播预览、回放、云台控制功能,如何利用萤石实现直播推流回流,实时监控播放,监控

🏆 前端领域优质创作者 1万+

问答式AI vs 智能体(Agent):它们有什么不同?

你肯定用过 ChatGPT 或文心一言——问它一个问题,它给你一个答案。AI Agent(AI智能体)。很多人搞不清楚:它们不都是"AI"吗?有什么区别?这篇文章用一个最简单的类比,彻底讲清楚这两者的本质差异。框架特点适合人群AutoGPT完全自主执行任务,链式思考开发者MetaGPT模拟团队协作,多角色分工开发者LangChain最流行的Agent开发框架开发者Dify可视化无代码搭建Agent非技术用户Coze(扣子)字节跳动出品,国内最易用普通用户WorkBuddy。

Johnny2004的专栏 445

1519. Number of Nodes in the Sub-Tree With the Same Label

Lc-1519 categories: [LeetCode] tags: [DFS, BFS, medium] 1519. Number of Nodes in the Sub-Tree With the Same Label 题目大意: 给定一个被标记为从0 到n-1的n个节点的树(一个连通,无向无循环的图),根节点为0结点, 并且每个结点也被标记了小写字母,所有的结点的小写字母按照结点顺序保存在一个字符串中labels, 第i个node的字母为labels[i], 同时给定一个二维数组edges,ed

JohnnyZXLiu的博客 229

ESM2蛋白预训练模型 蛋白质、氨基酸向量表示

参考: https://github.com/facebookresearch/esm https://huggingface.co/facebook/esm2_t33_650M_UR50D https://esmatlas.com/resources?action=fold tokenizer_对输入蛋白会头尾添加cls、eos特殊字符,占两个字符长度 参考:https://github.com/facebookresearch/esm 直接clone下来代码

weixin_42357472的博客 1万+

Leetcode 1519. Number of Nodes in the Sub-Tree With the Same Label (python)

题目 解法: 这个题目需要好好理解,首先题目没有给根几点,而只是给了根节点的值。同时提供的边是没有方向的,可能是parent指向child,也可以是child指向parent。 因为只提供了根节点的值和边,所以我们只能通过BFS来遍历整棵树,通过一个visited数组保证访问方向是从parent到child的。同时关于我们要求的答案,需要maintain一个count数组,因为都是lowercase,所以每行26的长度即可,这样方便后续的更新 同时这边利用了树形递归的方法,从child节点到parent

qq_37821701的博客 497

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

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

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

LeetCode Hot 100 二叉树专题(二)3 题(Java)

本篇文章共 3 题:543. 二叉树的直径、102. 二叉树的层序遍历、108. 将有序数组转换为二叉搜索树。 每道题都统一按「① 题目分析 & 解题思路 → ② 常见解法(附代码)及讲解 → ③ 知识点总结」的顺序组织;代码使用 Java 编写,节点定义沿用 LeetCode 默认的 TreeNode。

2401_88612756的博客 352

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

LeetCode Hot 100 链表专题 三· 3 题(Java)

收录题目:2. 两数相加、19. 删除链表的倒数第 N 个结点、24. 两两交换链表中的节点。 统一结构:① 题目分析与解题思路 → ② 常见解法(附代码)及讲解 → ③ 知识点总结。 贯穿三题的两条主线:虚拟头结点 dummy(统一处理头结点被修改的场景)与 指针修改顺序(避免断链、丢引用)。

2401_88612756的博客 481

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

LeetCode 每日一题 2026/11/2-2026/11/8

记录了初步解题思路 以及本地实现代码;并不一定为最优 也希望大家能一起探讨 一起进步

AlphaTao的博客 174

LeetCode 面试经典 150_多维动态规划_交错字符串(97_C++_中等)

LeetCode 面试经典 150_多维动态规划_交错字符串(97_C++_中等) 题目描述: 给定三个字符串 s1、s2、s3,请你帮忙验证 s3 是否是由 s1 和 s2 交错 组成的。 两个字符串 s 和 t 交错 的定义与过程如下,其中每个字符串都会被分割成若干 非空 子字符串: - s = s1 + s2 + ... + sn - t = t1 + t2 + ... + tm - |n - m| <= 1 - 交错 是 s1 + t

huayimenghan的博客 197

LeetCode 1861. 旋转盒子|Go 双指针解法

j >= 0,如果写成j>0,会漏掉第 0 列,最左侧石头处理失败旋转矩阵行列互换:原 m 行 n 列 → 结果 n 行 m 列,make 数组长度不要写反旋转公式m-1-i:是原总行数 m,不是 n!很容易写成n-1-i区分:本题和轮转数组(189)分组循环不一样!189:所有元素固定移动 k 步,需要 gcd 分组1861:障碍物分割成多个独立段,石头向段末尾挤,用双指针更合适。

2503_92676540的博客 175

Hash表:两数之和、字母异位词分组、最长连续序列 [力扣 Hot100]

三道高频哈希表应用题:两数之和(利用HashMap快速查找补数)、字母异位词分组(排序后作为键分组)、最长连续序列(通过HashSet去重并仅从序列起点扩展)。核心思想均为借助哈希结构优化查找效率,避免重复计算。同时提及双指针等其他解法思路,体现算法设计中“空间换时间”的典型策略。

2403_87560480的博客 195

LeetCode 3926. 统计有效单词的出现次数【分组循环】

核心思想:用分组循环,一趟遍历字符串,把一个个单词切出来,丢进哈希表统计频次。,先把所有片段拼接成完整文本字符串。,依次返回每个单词在文本里的出现次数。难点:内层循环的判断条件,区分。

2503_92676540的博客 166

力扣第526场周赛心得理解

思路:因为题目要求尽可能求出最小的最大值,而满足要求最小公约数为2,作为题目要求最小的最大值,先去求出它的最大公约数再通过value判断最左边是否大于0,以及value本身是否大于0,而index的位置只能为中间或者最右边,所以最后输出只能是value本身或者在这个基础上加相隔相应距离次数的结果。两个整数,是指将第二个整数的所有十进制数位拼接在第一个整数的所有十进制数位之后。如果不存在这样的数组,返回 -1。4097. 合并整数后的最小值。返回所有合并后得到的整数中的。合并,依此类推,直到将。

目前主攻编程,目标是把屏幕上的红波浪线变成流畅运行的程序♪(^∀^●)ノシ 198

LeetCode 0453.最小操作次数使数组元素相等:两次遍历(反向思维)

【LetMeFly】453.最小操作次数使数组元素相等:两次遍历(反向思维)

<font color="Pink">Tisfy的博客</font> 202

【算法学习笔记】LeetCode 15:三数之和(排序 + 双指针)

使用sort()对数组进行排序。理解排序后双指针的移动原理。使用外层循环固定一个数字。使用左右指针寻找另外两个数字。使用continue和while实现去重。理解的执行逻辑。将三层循环优化为排序 + 双指针,使时间复杂度从 O(n³) 降低到 O(n²)。

aqiu111111的博客 156

LeetCode100 15. 三数之和

本题通过排序+双指针优化三数之和。先对数组排序,外层遍历固定第一个数,内层用左右指针查找另两个数,使三数之和为0。通过剪枝(当前数>0则终止)和去重(跳过重复元素)提升效率。相比暴力或哈希法,该方法时间复杂度为O(n²),空间O(1),更高效优雅。

Shaoxingzong的博客 321

LeetCode hot 100 — 226. 翻转二叉树 | 101. 对称二叉树

自己稀里糊涂写了一版本居然还对了,我觉得我的思想就是很简单,这里就是要交换每一个节点的左右子树,所以套用了一下之前的中序遍历的迭代套路。一直在return False,但是没有给真正的正确答案一个出口(注意递归调用中出口 / 返回值很重要,或者说是最重要的)差一步美满....用的递归的写法,差一点点就满分了,先给出自己最开始写的代码。这道题的本质是对每一个节点执行相同的操作,并且交换哪个节点在先并不重要。你可以运用递归和迭代两种方法解决这个问题吗?,翻转这棵二叉树,并返回其根节点。给你一个二叉树的根节点。

Canmido的博客 128
上一篇: nanodet 训练细节解读
下一篇: leetcode 1443.Minimum Time to Collect All Apples in a Tree(收集苹果所需最短时间)
蓝羽飞鸟
博客等级 码龄8年 1万+粉丝 727原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝羽飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值