ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

Leetcode—94. 二叉树的中序遍历【简单】

Leetcode—94. 二叉树的中序遍历【简单】

2025每日刷题(246)

Leetcode—94. 二叉树的中序遍历

实现代码

/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */funcinorderTraversal(root*TreeNode)[]int{ans:=make([]int,0)vardfsfunc(root*TreeNode)dfs=func(root*TreeNode){ifroot==nil{return}dfs(root.Left)ans=append(ans,root.Val)dfs(root.Right)}dfs(root)returnans}

运行结果

之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!

返回列表