当前位置:网站首页>Force buckle 144 Preorder traversal of binary tree
Force buckle 144 Preorder traversal of binary tree
2022-07-07 07:59:00 【Yangshiwei....】
subject :
analysis :
Preorder traversal is to first self node , Then the left node , Last right node , We can write a recursive function to realize .
Code :
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public List<Integer> preorderTraversal(TreeNode root) {
List<Integer> list =new ArrayList();
first(root,list);
return list;
}
public void first(TreeNode node,List<Integer> list){
if(node!=null){
list.add(node.val);
if(node.left!=null){
first(node.left,list);
}if(node.right!=null){
first(node.right,list);
}
}
}
}
边栏推荐
- The principle and implementation of buffer playback of large video files
- buuctf misc USB
- [Stanford Jiwang cs144 project] lab4: tcpconnection
- [unity] several ideas about circular motion of objects
- Gslx680 touch screen driver source code analysis (gslx680. C)
- Value sequence (subsequence contribution problem)
- Jenkins remote build project timeout problem
- Leetcode 40: combined sum II
- A bit of knowledge - about Apple Certified MFI
- 【webrtc】m98 screen和window采集
猜你喜欢
QT learning 28 toolbar in the main window
Kbu1510-asemi power supply special 15A rectifier bridge kbu1510
3D reconstruction - stereo correction
Force buckle 145 Binary Tree Postorder Traversal
[experience sharing] how to expand the cloud service icon for Visio
2022焊工(初级)判断题及在线模拟考试
misc ez_usb
MySQL multi column index (composite index) features and usage scenarios
微信小程序基本组件使用介绍
php导出百万数据
随机推荐
Use and analysis of dot function in numpy
C language flight booking system
[P2P] local packet capturing
[SUCTF 2019]Game
Cnopendata geographical distribution data of religious places in China
C语言通信行程卡后台系统
有 Docker 谁还在自己本地安装 Mysql ?
[SUCTF 2019]Game
Pytorch parameter initialization
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
Route jump in wechat applet
自定义类加载器加载网络Class
Common validation comments
Zhilian + AV, AITO asked M7 to do more than ideal one
【VHDL 并行语句执行】
Most elements
【obs】win-capture需要winrt
LeetCode 90:子集 II
Rust versus go (which is my preferred language?)
Cnopendata list data of Chinese colleges and Universities