当前位置:网站首页>897. 递增顺序搜索树
897. 递增顺序搜索树
2022-06-23 06:14:00 【毕业_设计】
前言
C++是一种计算机高级程序设计语言,由C语言扩展升级而产生 ,最早于1979年由本贾尼·斯特劳斯特卢普在AT&T贝尔工作室研发。
C++既可以进行C语言的过程化程序设计,又可以进行以抽象数据类型为特点的基于对象的程序设计,还可以进行以继承和多态为特点的面向对象的程序设计。C++擅长面向对象程序设计的同时,还可以进行基于过程的程序设计。
C++拥有计算机运行的实用性特征,同时还致力于提高大规模程序的编程质量与程序设计语言的问题描述能力。
Java是一门面向对象的编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。Java语言作为静态面向对象编程语言的代表,极好地实现了面向对象理论,允许程序员以优雅的思维方式进行复杂的编程 。
Java具有简单性、面向对象、分布式、健壮性、安全性、平台独立与可移植性、多线程、动态性等特点 。Java可以编写桌面应用程序、Web应用程序、分布式系统和嵌入式系统应用程序等 。
Python由荷兰数学和计算机科学研究学会的吉多·范罗苏姆 于1990 年代初设计,作为一门叫做ABC语言的替代品。Python提供了高效的高级数据结构,还能简单有效地面向对象编程。Python语法和动态类型,以及解释型语言的本质,使它成为多数平台上写脚本和快速开发应用的编程语言,随着版本的不断更新和语言新功能的添加,逐渐被用于独立的、大型项目的开发。
Python解释器易于扩展,可以使用C语言或C++(或者其他可以通过C调用的语言)扩展新的功能和数据类型。Python 也可用于可定制化软件中的扩展程序语言。Python丰富的标准库,提供了适用于各个主要系统平台的源码或机器码。
2021年10月,语言流行指数的编译器Tiobe将Python加冕为最受欢迎的编程语言,20年来首次将其置于Java、C和JavaScript之上。
描述
给你一棵二叉搜索树的 root ,请你 按中序遍历 将其重新排列为一棵递增顺序搜索树,使树中最左边的节点成为树的根节点,并且每个节点没有左子节点,只有一个右子节点。
示例 1:
输入:root = [5,3,6,2,4,null,8,1,null,null,null,7,9]
输出:[1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9]
示例 2:
输入:root = [5,1,7]
输出:[1,null,5,null,7]
提示:
树中节点数的取值范围是 [1, 100]
0 <= Node.val <= 1000
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/increasing-order-search-tree
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
方法一:中序遍历之后生成新的树
算法
题目要求我们返回按照中序遍历的结果改造而成的、只有右节点的等价二叉搜索树。我们可以进行如下操作:
先对输入的二叉搜索树执行中序遍历,将结果保存到一个列表中;
然后根据列表中的节点值,创建等价的只含有右节点的二叉搜索树,其过程等价于根据节点值创建一个链表。
作者:LeetCode-Solution
链接:https://leetcode.cn/problems/increasing-order-search-tree/solution/di-zeng-shun-xu-cha-zhao-shu-by-leetcode-dfrr/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
class Solution {
public TreeNode increasingBST(TreeNode root) {
List<Integer> res = new ArrayList<Integer>();
inorder(root, res);
TreeNode dummyNode = new TreeNode(-1);
TreeNode currNode = dummyNode;
for (int value : res) {
currNode.right = new TreeNode(value);
currNode = currNode.right;
}
return dummyNode.right;
}
public void inorder(TreeNode node, List<Integer> res) {
if (node == null) {
return;
}
inorder(node.left, res);
res.add(node.val);
inorder(node.right, res);
}
}
作者:LeetCode-Solution
链接:https://leetcode.cn/problems/increasing-order-search-tree/solution/di-zeng-shun-xu-cha-zhao-shu-by-leetcode-dfrr/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。边栏推荐
- redux Actions may not have an undefined “type“ property. Have you misspelled a constant?
- TP6 安装拓展
- Summary of qvariant use in QT
- 899. 有序队列
- 【项目实训】线形箭头的变化
- DQL、DML、DDL、DCL的概念与区别
- MySQL Redo log Redo log
- [project training] details of linear components
- excel高级绘图技巧100讲(八)-Excel绘制WIFI图
- Solve the mining virus sshd2 (redis does not set a password and clear the crontab scheduled task)
猜你喜欢
![[STL] summary of deque usage of sequential containers](/img/33/65c54d14697ee43b2655ea1255d67d.png)
[STL] summary of deque usage of sequential containers
![[STL] summary of map usage of associated containers](/img/1d/1b6488ea47face0548500b1e1ec60d.png)
[STL] summary of map usage of associated containers

swagger3整合oauth2 认证token

redux Actions may not have an undefined “type“ property. Have you misspelled a constant?

【BULL中文文档】用于在 NodeJS 中处理分布式作业和消息的队列包

Media industry under the epidemic situation, small program ecology driven digital transformation exploration

mingw-w64、msys和ffmpeg的配置与编译

Idea automatically generates serialVersionUID

C语言学习总结

Children's programming for comprehensively cultivating students' mental thinking
随机推荐
Cloud box is deeply convinced to create a smart dual-mode teaching resource sharing platform for Nanjing No. 1 middle school
897. 递增顺序搜索树
MySQL basic query
The illustration shows three handshakes and four waves. Xiaobai can understand them
网页制作存在的一些难点
Children's programming for comprehensively cultivating students' mental thinking
Media industry under the epidemic situation, small program ecology driven digital transformation exploration
994. 腐烂的橘子-非递归法
反鸡汤致辞
Why does TCP protocol shake hands three times instead of two?
MySQL的意向共享锁、意向排它锁和死锁
总结的好处
【项目实训】线形箭头的变化
Xiaobai must see in investment and wealth management: illustrated fund buying and selling rules
关于职业态度
js 判断两个数组增加和减少的元素
cmder
【日常训练】513. 找树左下角的值
Eureka
[daily training] 513 Find the value in the lower left corner of the tree