LeetCode刷题笔录 Binary Tree Preorder Traversal

Unity集成阿里云语音AI:从麦克风录音到实时语音合成的全流程实现 本文详细介绍了在Unity中集成阿里云语音AI服务,实现从麦克风录音到实时语音合成的完整流程。通过调用阿里云的语音转文字和文字转语音接口,开发者可以快速为游戏或应用添加语音交互功能,提升用户体验。文章涵盖了环境配置、签名认证、音频处理及项目集成等核心步骤,并提供了实用的调试技巧。 阅读详情

Given a binary tree, return the preorder traversal of its nodes' values.

For example:
Given binary tree {1,#,2,3},

   1
    \
     2
    /
   3

return [1,2,3].

Note: Recursive solution is trivial, could you do it iteratively?

递归的不说了。记得本科数据结构的书里讲过了非递归的实现方式,需要自己手写一个stack。Preorder是三种DFS里最好实现的,每个node都是在第一次被从stack中pop出来后就进行访问。

逻辑:

1.把root放到stack里

2.从stack里pop出一个node,进行访问

3.右儿子放到Stack里

4.左儿子放到stack里

public class Solution {
    public ArrayList<Integer> preorderTraversal(TreeNode root) {
        ArrayList<Integer> result = new ArrayList<Integer>();
        if(root == null)
            return result;
        Stack<TreeNode> stack = new Stack<TreeNode>();
        stack.push(root);
        while(!stack.isEmpty()){
            TreeNode node = stack.pop();
            result.add(node.val);
            if(node.right != null)
                stack.push(node.right);
            if(node.left != null)
                stack.push(node.left);
        }
        return result;
    }
}


【附源码】Node.js毕业设计高校院级校友信息管理系统(Express) 首先,该系统可以提高高校对校友信息管理的效率和准确性。通过系统提供的查询功能,高校可以方便地获取校友的最新联系方式和动态,及时了解校友的发展情况,为校友提供更好的服务和支持。总之,开发高校院级校友信息管理系统将为高校提供一个高效、便捷的工具,有助于提升校友管理水平和服务质量,促进高校与校友之间的良好互动关系。通过使用前端技术HTML、CSS、JavaScript和Vue框架,结合后端技术Node.js和Express框架,以及MySQL数据库,可以实现对校友信息的快速录入、查询、修改和删除等操作。 阅读详情

相关推荐

深入理解光流法外推雷达回波

背景介绍 鉴于本人实在太过疲惫和劳累,一些简单的便于理解的废话就不在记录,耗费两天时间研究了一下光流法,本帖用于记录学习过程中源码的难点细节。 使用光流预测的核心有两个利用多张连续回波图像(变分)或者相邻两张回波图(交叉相关,LK等)计算出光流场(速度矢量场),之后利用半拉格朗日方法进行外推。 半拉格朗日方法 三时间步半拉格朗日方法,其核心公式如下 但这个有点难理解,但看一维的图就很好理解 它的核心就是迭代求Am(位移矢量),如果理解困难的话,其实质上就是通过未来迭代(猜)出当前时刻的Am找到过去的假设

weixin_44695861的博客 6033

LeetCode-Binary Tree Preorder Traversal

题目:https://oj.leetcode.com/problems/binary-tree-preorder-traversal/ Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,#,2,3}, 1

Hama White 的博客 1132

CentOS7下快速修复libssl.so.1.1缺失问题(附腾讯云镜像加速下载)

本文详细介绍了在CentOS7系统中快速修复libssl.so.1.1缺失问题的工程化实践方案。通过编译安装OpenSSL 1.1.x版本、配置动态链接器及创建符号链接等步骤,有效解决共享对象文件缺失问题,并提供了腾讯云镜像加速下载的优化方案,帮助开发者高效部署现代应用。

weixin_33711647的博客 367

[leetcode-二叉树先序遍历]--144.Binary Tree Preorder Traversal

Question 144. Binary Tree Preorder Traversal Given a binary tree, return the preorder traversal of its nodes’ values. For example: Given binary tree {1,#,2,3}, 1 \ 2

惜暮 1225

掌握SiOME:从零构建OPC UA信息模型的完整指南

本文是掌握SiOME工具的完整指南,详细介绍了如何利用这款免费且强大的OPC UA建模工具,从零开始构建信息模型。内容涵盖从获取软件、创建命名空间、定义对象类型与变量,到添加方法、生成XML文件,并最终将其集成到开源的open62541服务器中。通过可视化建模,开发者可以高效、准确地设计复杂模型,大幅提升工业物联网与自动化项目的开发效率。

tcp8optimizer的博客 515

无感无刷电机三段式启动避坑指南:从预定位到闭环切换的STM32代码实现

本文深入解析无感无刷电机的三段式启动流程,涵盖预定位、启动加速与闭环切换三大阶段。重点对比了恒频升压、恒压升频与升频升压三种核心启动策略的优劣,并提供了基于STM32的详细状态机代码实现与关键参数调试指南,帮助工程师有效规避启动失步、线圈过热等常见问题,实现稳定可靠的无感驱动。

herb5的博客 535

LeetCode刷题笔录Construct Binary Tree from Preorder and Inorder Traversal

Given preorder and inorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tree.

likecool21的专栏 786

Vector CANoe VT2516A实战:从硬件连接到CAPL脚本的完整配置指南

本文详细介绍了Vector CANoe VT2516A板卡从硬件连接到CAPL脚本编写的完整配置指南。涵盖硬件接线原则、VT System配置避坑技巧、系统变量创建规范、可视化Panel设计、CAPL脚本调试及典型故障排查案例,帮助工程师快速掌握VT2516A板卡的应用实践,提升汽车电子测试效率。

weixin_30608503的博客 254

LeetCode刷题笔录 Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo

likecool21的专栏 1万+

pgsql行列转换

‌是PostgreSQL中的一个函数,用于将一个字符串根据正则表达式进行分割,并将结果返回为一个表格,每个分割后的部分作为一行‌‌。string_agg() 函数是 PostgreSQL 中的一个聚合函数,用于将一个列中的值连接成一个字符串。

chimchim66的博客 3501

5、数字图像采集:X射线成像技术全解析

本文全面解析了数字图像采集中的X射线成像技术,涵盖数字X射线探测器、荧光透视与血管造影、乳腺摄影以及计算机断层扫描(CT)的图像重建原理。详细介绍了TFT平板探测器的优势、DSA技术在血管成像中的应用、乳腺摄影对高对比度和分辨率的需求,以及CT中基于Radon变换和滤波反投影的重建方法。同时探讨了噪声、部分容积效应、金属伪影和运动伪影等常见问题及其影响。最后总结了各类X射线成像技术的特点与应用场景,并展望了未来在图像质量提升和剂量优化方面的技术发展方向。

l6m7n8的博客 128

LeetCode刷题笔录 Two Sum

Two Sum Given an array of integers, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the two numbers such that they add up to the

likecool21的专栏 1万+

SAP 批量修改 工艺路线 和 BOM

1、在运维的过程中经常会遇到用户需要批量更改组件,或者是批量更改数量,还是组件里面的一些标识,当处理这些批量数据处理的业务时,BOM的批量更改一个想到的就是CS20,但是CS20当BOM需要替换的时候就不是很适用。当前工作区域:选择 SAP_ITEM 对BOM行项目进行变更,工艺路线也是可以批量更改的,根据实际的业务进行选择,我这里选择的就是BOM的组件变更。5、本博客将使用新的一种方式进行BOM的批量变更,标准的事务代码:CEWB对BOM进行批量更改。3、使用LSMW的方式进行BOM的批量更改。

我小时候很黑的博客 4095

LeetCode刷题笔录 Validate Binary Search Tree

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key.Th

likecool21的专栏 6928

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Stanford Algorithms学习:Clustering 2

这是紧接上面的一道题,比较有趣 Question 2 In this question your task is again to run the clustering algorithm from lecture, but on a MUCH bigger graph. So big, in fact, that the distances (i.e., edge costs

likecool21的专栏 2567

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

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

Stanford Algorithms学习:Clustering

第二周的第一个编程作业,是利用贪婪算法来实现一个clustering的问题,和ML里学的unsupervised learning差不多。 Question 1 In this programming problem and the next you'll code up the clustering algorithm from lecture for computing a

likecool21的专栏 2507

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

LeetCode 刷题笔录 Add Two Numbers

You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link

likecool21的专栏 1806

LeetCode刷题笔录Edit Distance

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operations permitted on a word:

likecool21的专栏 1296

LeetCode刷题笔录Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

likecool21的专栏 1109

LeetCode刷题笔录 Pascal's Triangle II

Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 这题比较简单

likecool21的专栏 1043

LeetCode刷题笔录Unique Binary Search Trees

这里有个讲解(印度人口音真难懂)

likecool21的专栏 1043

LeetCode刷题笔录Container With Most Water

Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin

likecool21的专栏 1001

LeetCode刷题笔录 Reverse Integer

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 随手写的一个,正常的读出每一位的数字然后反序: import java.lang.Math; public class Solution { public int revers

likecool21的专栏 941

LeetCode刷题笔录Sum Root to Leaf Numbers

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is the root-to-leaf path 1->2->3 which represents the number 123. Find the tota

likecool21的专栏 878

LeetCode刷题笔录Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the f

likecool21的专栏 865

LeetCode刷题笔录Convert Sorted Array to Balanced Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 这题可以kan'chu'lai

likecool21的专栏 855
上一篇: LeetCode刷题笔录Linked List Cycle
下一篇: LeetCode刷题笔录 Binary Tree Inorder Traversal
likecool21
博客等级 码龄14年 14粉丝 123原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值