leetcode 226. Invert Binary Tree(二叉树反转)

tinyddp使用详解 tinyddp使用详解: 1、创建服务端,客户端 2、远程调用 3、发布订阅 4、设置日志 阅读详情

在这里插入图片描述
把二叉树所有节点的的左右子树反转。

思路:

既然所有节点的左右子树进行反转,就需要对所有节点遍历。

选择前序遍历,因为先遍历root,然后反转它的左右子树,再对左右子树遍历。

class Solution {
    public TreeNode invertTree(TreeNode root) {
        preOrder(root);
        return root;
    }

    void preOrder(TreeNode root) {
        if(root == null) return;
        TreeNode tmp = root.left;
        root.left = root.right;
        root.right = tmp;

        preOrder(root.left);
        preOrder(root.right);
    }
}
C语言实现惯性导航初始对准全部核心代码 惯性导航初始对准包括间接粗对准和卡尔曼滤波精对准,其中。为基于卡尔曼滤波的精对准,其中。 阅读详情

相关推荐

Codex CLI 接入智谱 GLM-5.1 完整教程

Codex CLI 是 OpenAI 推出的命令行 AI 编程工具,支持自主读取文件、执行命令、编写代码等操作,是目前最火的终端 AI 编程工具之一。通过 CLIProxyAPI 代理,我们成功将 Codex CLI 与智谱 GLM-5.1 模型对接,核心在于解决 Responses API 与 Chat Completions API 的协议转换问题。✅成熟稳定:CLIProxyAPI 社区活跃(4.7k fork),持续维护✅完整兼容:支持流式/非流式、function calling✅低成本。

u011831527的博客 2605

Leetcode 226 Invert Binary Tree 反转二叉树

反转一棵二叉树

(ง •̀_•́)ง 810

AURIX-TC3xx-GTM详解六-DPLL(Digital PLL Module)-寄存器1-DPLL寄存器

主要有下图这些寄存器2、

m0_69929716的博客 446

Leetcode 226: Invert Binary Tree(二叉树反转 递归、非递归实现)

nvert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem was inspired by this original tweet by Max Howel

哈哈的个人专栏 2万+

VBA学习笔记6:将多个工作表中满足条件的数据汇总到同一个工作表

VBA学习笔记6:将多个工作表中满足条件的数据汇总到同一个工作表

weixin_45355881的博客 4713

论文必备 - YOLOv12热力图可视化,支持指定模型,指定显示层,设置置信度,以及10种可视化实现方式

本文带来的是YOLOv12热力图可视化功能,支持,以及。我们经常看到一些论文里绘制了不同的热力图,一方面能够直观的感受其模型的有效性,另一方面也丰富了论文内容。特别是在使用了注意力模块的网络中,热力图就可以验证注意力机制是否真正聚焦到了预期的重要特征上,以便对模型的有效性和合理性进行评估。例如这篇文章中展示的,就很能够表达作者改进后的模型相比之前模型的优越性。

Limiiiing的博客 1711

LeetCode :226. Invert Binary Tree 反转二叉树

试题 Invert a binary tree. Example: Input: 4 / 2 7 / \ / 1 3 6 9 Output: 4 / 7 2 / \ / 9 6 3 1 Trivia: This problem was inspired by this original tweet by Max Howell: Goo...

心之所向 197

基于FPGA的以太网设计(1)----大白话解释什么是以太网

基于FPGA的千兆以太网设计(1)----大白话解释什么是以太网

孤独的单刀 3896

第27题:Leetcode226: Invert Binary Tree反转二叉树

翻转一棵二叉树。 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1  思路 如果根节点存在,就交换两个子树的根节点,用递归,从下至上。、 解一: auto tmp = invertTree(root->...

Lightmare625 236

uniapp(全端兼容) - 最新详细实现支付键盘功能组件,从底部弹出数字键盘输入支付密码进行付款交互效果,自定义支付密码键盘仿微信、支付宝支付键盘,1~9密码数字键盘,电商支付(详细示例代码复制运行

uniapp,微信小程序,自定义数字键盘,输入支付密码的键盘组件,uniapp小程序如何实现从底部弹出输入支付密码自定义键盘功能,uniapp小程序密码支付键盘组件插件,自定义数字键盘输入页面,怎么封装底部弹窗自定义数字键盘用于输入支付密码,uniapp小程序仿类似电商支付密码输入模态框,uniapp微信小程序平台实现自定义支付密码键盘,uniapp 密码支付,数字键盘,安全键盘,交易键盘,交易密码,交易密码输入框,uniapp自定义支付键盘: uniapp自定义支付键盘,uniapp小程序端实现键盘输入支

✅ 精选推荐文章 2910

修改legged_gym地形后仍然是平地,如何解决?

🏆 本文收录于《全栈Bug调优(实战版)》专栏,致力于分享我在项目实战过程中遇到的各类Bug及其原因,并提供切实有效的解决方案。无论你是初学者还是经验丰富的开发者,本文将为你指引出一条更高效的Bug修复之路,助你早日登顶,迈向财富自由的梦想🚀!同时,欢迎大家关注、收藏、订阅本专栏,更多精彩内容正在持续更新中。让我们一起进步,Up!Up!Up!    备注: 部分问题/难题源自互联网,经过精心筛选和整理,结合数位十多年大厂实战经验资深大佬经验总结所得,数条可行方案供所需之人参考。

**My Coding Family** 1570

LeetCode 226. Invert Binary Tree(反转二叉树)

原题网址:https://leetcode.com/problems/invert-binary-tree/ Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 思路:递归调用,对左右子节

James Pan 988

【离线OCR】微信离线实现图片OCR文本和表格识别

基于微信本地OCR引擎(由最新版微信自动安装)。通过Python对其官方调用逻辑进行完整翻译和封装,使开发者可以用简单的API调用其强大的OCR功能。

专注于医院数据分析技术与系统开发的创作与分享。 2639

leetcode 226. Invert Binary Tree 左右反转二叉树

     

qq_38734403的博客 239

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

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

LeetCode 226. Invert Binary Tree(反转二叉树)

Invert a binary tree. Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem was inspired by this origin...

nicolelili1的专栏 133

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

[LeetCode]226. Invert Binary Tree(反转二叉树)

226. Invert Binary TreeInvert a binary tree.翻转二叉树 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 用递归,交换各个节点的左右节点 代码如下:C++/** * Definition for a bin

whl_program的博客 287

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

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

LeetCode226:Invert Binary Tree 二叉树反转

题目226. Invert Binary TreeQuestionEditorial SolutionMy SubmissionsTotal Accepted:109341Total Submissions:230799Difficulty:EasyInvert a binary tree.4 /\ 27 /\/\ 1...

weixin_34138255的博客 72

【LeetCode-面试算法经典-Java实现】【226-Invert Binary Tree(反转二叉树)】

【226-Invert Binary Tree(反转二叉树)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】代码下载【https://github.com/Wang-Jun-Chao】原题  Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9  to 4 / \ 7

https://github.com/Wang-Jun-Chao 6296

[LeetCode]226. Invert Binary Tree--反转二叉树

Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem was inspired by this

iamxiaofeifei的博客 346

LeetCode 226. Invert Binary Tree--反转二叉树--C++,Python解法--递归,迭代做法

LeetCode 226. Invert Binary Tree–反转二叉树–C++,Python解法 LeetCode题解专栏:LeetCode题解 我做的所有的LeetCode的题目都放在这个专栏里,大部分题目Java和Python的解法都有。 题目地址:Invert Binary Tree - LeetCode Invert a binary tree. Example: Input:...

个人博客 547

leetcode 226. Invert Binary Tree 反转二叉树 + DFS深度优先搜索

Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia: This problem was inspired by this original tweet by Max Howell: Go

JackZhangNJU的专栏 440

java反转二叉树_LeetCode 之 JavaScript 解答第226题 —— 翻转二叉树(Invert Binary Tree)...

Time:2019/4/21Title: Invert Binary TreeDifficulty: EasyAuthor: 小鹿题目:Invert Binary Tree(反转二叉树)Invert a binary tree.反转二叉树Example:Input:4/ \2 7/ \ / \1 3 6 9Output:4/ \7 2/ \ / \9 6...

weixin_29763721的博客 162

※ Leetcode - Tree - 226. Invert Binary Tree(反转二叉树 使用二级指针交换两个指针的地址)

1. Problem Description Invert a binary tree.        4    /   \   2     7  / \     / \ 1   3  6  9   to      4    /   \   7     2  / \     / \ 9   6  3  1   Trivia: This problem was in

Dancinglikelink 628

LeetCode 226 Invert Binary Tree题解

题目地址:https://leetcode.com/problems/invert-binary-tree/ 题目: Invert a binary tree. 反转一颗二叉树 4 / \ 2 7 / \ / \ 1 3 6 9 to 至 4 / \ 7 2 / \ / \ 9 6

赞美月亮的专栏 794

LeetCode题解-226-Invert Binary Tree

尽管写LeetCode解答主要是为了自己整理思路,但是如果对您也正好有帮助,请点个赞给菜鸟一点鼓励吧 :-) 原题 解法分析 解法1使用了递归; 解法2使用了迭代法,为广度优先的层级遍历。 解法1 解法分析 递归。反转左子树与右子树,最后交换根节点的左子树与右子树。 代码 public class Solution226_recursive {

WangT443的博客 448

LeetCode 之 JavaScript 解答第226题 —— 翻转二叉树(Invert Binary Tree)

Time:2019/4/21 Title: Invert Binary Tree Difficulty: Easy Author: 小鹿 题目:Invert Binary Tree(反转二叉树) Invert a binary tree. 反转二叉树 Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Outp...

小鹿动画学编程 1145
上一篇: leetcode 783. Minimum Distance Between BST Nodes(BST节点的最小距离)
下一篇: CenterMask paper笔记
蓝羽飞鸟
博客等级 码龄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、付费专栏及课程。

余额充值