当前位置:网站首页>Xiaohei's leetcode journey: 94. Inorder traversal of binary trees (supplementary Morris inorder traversal)
Xiaohei's leetcode journey: 94. Inorder traversal of binary trees (supplementary Morris inorder traversal)
2022-08-09 23:14:00 【little black invincible】
Xiaohei realizes after learning
# Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right = rightclass Solution:def inorderTraversal(self, root: Optional[TreeNode]span>) -> List[int]:arr = []while root:# pointer to left childpre = root.left# The left child is not empty (the "rightmost" node of the left child is connected to the root, and the root becomes the left child)if pre:# Find the rightmost childwhile pre.right and pre.right != root:pre = pre.right# The rightmost child points to root, then print root, then root is root.rightif pre.right:#pre.right = Nonearr.append(root.val)root = root.right# it is empty, point the right pointer of the rightmost child to root, then root = root.leftelse:pre.right = rootroot = root.left# left child is empty (print, root becomes right child)else:arr.append(root.val)root = root.rightreturn arr
边栏推荐
- Referenced file contains errors 完美解决方法
- Reinforcement Learning Weekly Issue 57: DL-DRL, FedDRL & Deep VULMAN
- cadence中复制一部分PCB到另一个PCB中去
- Pagoda measurement - building LightPicture open source map bed system
- LED闪烁 闪灯芯片IC 手电筒IC 闪灯控制IC 闪烁IC流水灯
- 题解:Edu Codeforces 109(div2)
- STC8H development (15): GPIO drive Ci24R1 wireless module
- TF使用constant生成数据
- 几种绘制时间线图的方法
- mysql配置参数详解[通俗易懂]
猜你喜欢
FS4066耐高压1到4节内置MOS的锂电池充电管理芯片
Pagoda measurement - building LightPicture open source map bed system
Shanghai Konan SmartRocket series product introduction (3): SmartRocket iVerifier computer interlocking system verification tool
Word怎么制作双面席卡?使用Word制作双面席卡方法
ACM MM 2022 | Cloud2Sketch: 长空云作画,AI笔生花
万字总结:分布式系统的38个知识点
[Implementation of the interface for adding, deleting, checking, and modifying a double-linked list]
Jmeter 使用正则表达式提取器将返回值全部保存到一个文件中
[corctf 2022] 部分
LoRa无线技术在物联网应用市场的概况和发展
随机推荐
SQLi-LABS Page-2 (Adv Injections)
AI识万物:从0搭建和部署手语识别系统
APP automation test framework - UiAutomator2 introductory
Word怎么设置图片衬于文字下方?两种方法教你设置Word图片衬于文字下方
laravel table migration error [easy to understand]
上海控安SmartRocket系列产品推介(三):SmartRocket iVerifier计算机联锁系统验证工具
Sudoku | Backtrack-7
Usage of placeholder function in Tensorflow
CVPR22 Oral | shunt through multi-scale token polymerization from attention, code is open source
[corctf 2022] section
Technology Sharing | How to Handle Header Cookies in Interface Automation Testing
np中的round函数,ceil函数与floor函数
CVPR22 Oral|通过多尺度token聚合分流自注意力,代码已开源
Wps下划线怎么弄?Wps添加下划线的最全方法
抽象类 or 接口
Interpretation of the paper (DropEdge) "DropEdge: Towards Deep Graph Convolutional Networks on Node Classification"
小黑leetcode清爽雨天之旅,刚吃完宇飞牛肉面、麻辣烫和啤酒:112. 路径总和
基于Docker构建MySQL主从复制数据库
ACM MM 2022 | Cloud2Sketch: Painting with clouds in the sky, AI brush strokes
Tensorflow模型整体构建流程