剑指Offer:二叉树的镜像

ESP32 UART实战:ESP-IDF 5.4.4配置、RS485通信与问题排查 串口通信(UART)是嵌入式开发中历史最悠久、使用最广泛的通信方式之一。它通过两根数据线实现异步收发,具备连接简单、适用性广等特点,广泛应用于日志输出、传感器数据采集、GPS定位及工业现场设备对接。理解UART的帧格式、波特率误差、电平转换等基本原理,是排查乱码、丢字节等高频故障的关键。在ESP32平台上,基于ESP-IDF框架进行UART开发时,开发者不仅需要掌握基础的参数配置与收发调用,还需熟悉事件队列、DMA、RS485半双工控制等进阶用法。本文以ESP-IDF 5.4.4在Ubuntu环境下的安装为 阅读详情

题目描述

操作给定的二叉树,将其变换为源二叉树的镜像。 
输入描述:

二叉树的镜像定义:源二叉树 
    	    8
    	   /  \
    	  6   10
    	 / \  / \
    	5  7 9 11
    	镜像二叉树
    	    8
    	   /  \
    	  10   6
    	 / \  / \
    	11 9 7  5
/**
public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;


    public TreeNode(int val) {
        this.val = val;


    }


}
*/
public class Solution {
    public void Mirror(TreeNode root) {
        if( root == null) return;
        TreeNode tmp = null;
        tmp = root.left;
        root.left = root.right;
        root.right = tmp;
        
        Mirror(root.left);
        Mirror(root.right);
    }
}



富芮坤fr8008gp 240X280 lvgl项目启动 fr8008gp_240X280_lvgl项目启动 阅读详情

相关推荐

【鸿蒙实战开发】HarmonyOS申请调试签名证书过程

这份鸿蒙(HarmonyOS NEXT)资料包含了鸿蒙开发必掌握的核心知识要点,内容包含了(ArkTS、ArkUI开发组件、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战等等)鸿蒙(HarmonyOS NEXT)技术知识点。

HarmonyOS_002的博客 3561

剑指Offer(十八):二叉树的镜像

剑指Offer(十八):二叉树的镜像 搜索微信公众号:'AI-ming3526'或者'计算机视觉这件小事' 获取更多算法、机器学习干货 csdn:https://blog.youkuaiyun.com/baidu_31657889/ github:https://github.com/aimi-cn/AILearners 一、引子 这个系列是我在牛客网上刷《剑指O...

小明的博客 1467

电工电子实验——3BIT延时电路的设计与实现

设计一个 3BIT延时电路。 设计分析: Ⅰ.根据触发器的特性,只有来两个触发脉冲时才能恢复到原来的状态。也就是说触发器的输出信号比触发信号延迟了一个触发脉冲周期即1bit。据此3bit就需要3个触发器。 Ⅱ.输出要可控就要加一控制器,可用选择器实现。 Ⅲ.为便于观察输出信号的延迟,可设计一个F1信号。

qq_55543315的博客 1128

剑指Offer(Python多种思路实现):二叉树的镜像

剑指Offer(Python多种思路实现):二叉树的镜像 面试27题: 题目:二叉树的镜像 题:操作给定的二叉树,将其变换为源二叉树的镜像。 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \...

weixin_44151089的博客 1013

Pandas实战指南:从数据结构到清洗聚合的完整解析

在数据分析工作中,表格数据处理是最常见的需求,无论是电商运营还是量化交易,都离不开对结构化数据的清洗与转换。Python生态中,Pandas凭借Series与DataFrame两种核心数据结构,将数据标签与数值绑定,实现自动对齐,极大简化了数据操作流程。它不仅是数据清洗的利器,也是分组聚合、透视表分析和时间序列处理的基础工具。掌握Pandas,意味着能够高效完成从数据读取、缺失值处理、类型转换到分组统计的完整分析流水线,将重复性报表工作自动化。本文基于实际使用经验,系统梳理Pandas的核心概念、常用操作、

weixin_30768881的博客 258

C# 通俗易懂的介绍基础知识(七)——栈Stack(从日常生活开始讲解)

C# 通俗易懂的介绍基础知识(七)——栈Stack(从日常生活开始讲解) 大家好,我是菌菌巧乐兹,励志用最简单的语言来讲解程序知识点。

菌菌兹的博客 1669

剑指offer:树的子结构、二叉树的镜像、对称的二叉树

剑指offer:树的子结构、二叉树的镜像、对称的二叉树 题目: 树的子结构: 输入两棵二叉树A和B,判断B是不是A的子结构。 分析: 1. 查找树A中与树B根节点一样的结点(树的遍历)。 2. 判断A中以该结点为根节点的子树是不是和B具有一样的结构。 注:在写树的代码的时候,要时刻注意该地址是否可能是nullptr /*s...

starflyyy的博客 149

一个测试工程师走进一家酒吧……

一个测试工程师走进一家酒吧,要了一杯啤酒;一个测试工程师走进一家酒吧,要了一杯咖啡;一个测试工程师走进一家酒吧,要了 0.7 杯啤酒;一个测试工程师走进一家酒吧,要了-1 杯啤酒;一个测试...

字节跳动技术团队官方博客 4887

剑指offer27:二叉树镜像 python

剑指offer27:二叉树镜像 python题目叙述递归方法非递归方法 题目叙述 递归方法 时间久,但是占用内存少 // An highlighted block class Solution: def mirrorTree(self, root: TreeNode) -> TreeNode: if not root: return None root.left, root.right = root.right, root.left

weixin_43494312的博客 193

Python爬虫实战:微信小程序内容采集的全面指南

在移动互联网时代,微信小程序已成为企业和个人提供服务的重要渠道。小程序中包含了大量有价值的信息,但微信官方并未提供便捷的数据获取接口。本文将详细介绍如何使用Python爬虫技术采集微信小程序内容,包括最新技术方案、完整代码实现以及应对各种反爬机制的策略。小程序运行在微信封闭环境中,无法直接访问数据通信主要通过HTTPS加密传输内容动态加载,依赖JavaScript渲染微信有严格的反爬机制。

2201_76125261的博客 3117

基于Simulink与MATLAB的七轴OpenArm机械臂逆运动学仿真与轨迹规划完整指南

本文详细介绍了七自由度OpenArm机械臂在MATLAB/Simulink环境下的运动学仿真与轨迹规划实现方法。首先建立了机械臂的DH参数模型,验证了正运动学计算;随后提出了两种逆运动学求解算法(数值迭代法和臂型角参数化解析法)的MATLAB实现方案;最后在Simulink中搭建了完整的轨迹规划与控制系统。研究解决了七自由度冗余机械臂特有的多解性、奇异性和关节限位约束等核心问题,为OpenArm机械臂的运动控制提供了完整的技术方案和可运行代码实现。

AI的内部世界的博客 684

剑指offer面试题27(java版):二叉树的镜像

welcome to my blog 剑指offer面试题27(java版):二叉树的镜像 题目描述 操作给定的二叉树,将其变换为源二叉树的镜像。 思路 使用递归 只要当前节点不是null, 就交换其左右子节点 不带返回值的递归 public class Solution { public void Mirror(TreeNode root) { if(root !=...

littlehaes的博客 328

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

剑指Offer17:二叉树的镜像

剑指Offe17:二叉树的镜像 1.题目 操作给定的二叉树,将其变换为源二叉树的镜像。 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ ...

七小琦 183

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

WINCC7.3破解文件

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

剑指Offer: 二叉树的镜像

剑指Offer: 二叉树的镜像 题目描述 操作给定的二叉树,将其变换为源二叉树的镜像。 样例 输入树: 8 / \ 6 10 / \ / \ 5 7 9 11 [8,6,10,5,7,9,11,null,null,null,null,null,null,null,null] 输出树: 8 / \ 10 6 / ...

Erice_s的博客 196

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

剑指offer第18题:二叉树的镜像

剑指offer第18题:二叉树的镜像题目描述二叉树的镜像分析观测镜像二叉树的特点源码 题目描述 二叉树的镜像 操作给定的二叉树,将其变换为源二叉树的镜像。 分析 观测镜像二叉树的特点 对镜像二叉树的特点进行分析,不难发现,对于根节点而言,其值不变,其左、右儿子互换位置,并且左右子树都变成了镜像二叉树。 源码 /* struct TreeNode { int val; struct TreeN...

可爱的小腊肉 252

剑指offer算法题018:二叉树的镜像

小编在求职找找工作期间剑指offer上的算法题刷了很多遍,并且每道题小编当时都总结了一种最适合面试时手撕算法的最优解法。考虑到剑指offer算法题在面试中的高频出现,小编每天和大家分享一道剑指offer上的算法题,以及小编总结的答案。下面是第018道剑指offer算法题: 题目描述 操作给定的二叉树,将其变换为源二叉树的镜像。 二叉树的镜像定义:源二叉树 分析: 典型的递归问题,递归在树相关问题中很常见,不是很难,大家多写写画画就可以理解了,算法题一定要建立自己的理解上 /** public class

我的博客 299

剑指offer——树:二叉树的镜像

本文实现了一个二叉树的镜像翻转算法。通过递归方式,先判断节点是否为空,若非空则交换其左右子节点,然后递归处理左右子树。该方法简洁高效,时间复杂度为O(n),空间复杂度为O(h),其中h为树的高度。关键点在于使用临时变量完成节点交换,并确保递归处理所有子树。该实现适用于任何二叉树结构,能够正确生成原树的镜像版本。

weixin_74681777的博客 316

《剑指Offer》面试题19:二叉树的镜像

《剑指Offer》 P125面试题19:二叉树的镜像题目:

(●—●) 354

剑指offer:二叉树的镜像

题目描述 操作给定的二叉树,将其变换为源二叉树的镜像。 输入描述: 二叉树的镜像定义:源二叉树 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树 8 / \ 10 6 / \ / \ 11 9 7 5 ...

在未来等你的专栏 132

剑指offer: 二叉树的镜像

题目描述:操作给定的二叉树,将其变换为源二叉树的镜像。 二叉树的镜像,顾名思义就是从源二叉树得到一个镜像的二叉树 解决流程: 1.首先,不管是源二叉树还是镜像二叉树,他的根节点都是不会发生改变的 2.然后进行左右子树的交换 3.递归处理。 3.在树的问题上我们使用递归处理更加的清晰,方便。 /* struct TreeNode { int val; struc...

Shile975的博客 220

剑指offer: 二叉树的镜像

题目:操作给定的二叉树,将其变换为源二叉树的镜像。 二叉树的镜像定义: 源二叉树: 8 / \ 6 10 / \ / \ 5 7 9 11 镜像二叉树: 8 / \ 10 6 / \ / \ 11 9 7 5 思路:交换6和10下面的...

feifeifei_yu的博客 136

剑指offer:二叉树的镜像

题目描述 操作给定的二叉树,将其变换为源二叉树的镜像。 /* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ class Solution { public: void Mirror(TreeNode *pRoot) { //1.递归

Everglow_zbz的博客 158
上一篇: 剑指Offer:树的子结构
下一篇: 构造MaxTree O(n)方法
Fly_TheWind
博客等级 码龄11年 53粉丝 110原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值