当前位置:网站首页>Structure binary tree from inorder and postorder traversal for leetcode topic analysis
Structure binary tree from inorder and postorder traversal for leetcode topic analysis
2022-06-23 09:08:00 【ruochen】
Given inorder and postorder traversal of a tree, construct the binary tree.
Note:
You may assume that duplicates do not exist in the tree.
int p;
int[] postorder;
int[] inorder;
public TreeNode buildTree(int[] inorder, int[] postorder) {
this.p = postorder.length - 1;
this.inorder = inorder;
this.postorder = postorder;
return buildTree(0, postorder.length);
}
TreeNode buildTree(int start, int end) {
if (start >= end) {
return null;
}
TreeNode root = new TreeNode(postorder[p]);
int i;
for (i = start; i < end && postorder[p] != inorder[i]; i++)
;
p--;
root.right = buildTree(i + 1, end);
root.left = buildTree(start, i);
return root;
}边栏推荐
- 523. Continuous Subarray Sum
- 173. Binary Search Tree Iterator
- 636. Exclusive Time of Functions
- How to use "tomato working method" in flowus, notation and other note taking software?
- The results of CDN node and source station are inconsistent
- Combination sum II of leetcode topic analysis
- node request模塊cookie使用
- 【活动报名】SOFAStack × CSDN 联合举办开源系列 Meetup ,6 月 24 日火热开启
- [qnx hypervisor 2.2 user manual]6.1 using the QNX hypervisor system
- Simple student management
猜你喜欢

三层架构与SSM之间的对应关系

Le rapport d'analyse de l'industrie chinoise des bases de données a été publié en juin. Le vent intelligent se lève, les colonnes se régénèrent

Geoserver添加mongoDB数据源

S5P4418裸机编程的实现(替换2ndboot)

点击添加下拉框
Redis学习笔记—持久化机制之AOF

Testing -- automated testing selenium (about API)

瞄准海外宠物市场,「Grasphand 」做了一款独立于手机的智能追踪产品 | 早期项目

In depth interpretation of poca smart contract platform gear: the road to parallel architecture public chain

Quartz Crystal Drive Level Calculation
随机推荐
js 用**遮罩身份证以及手机号的重要数据
自定义标签——jsp标签增强
Le rapport d'analyse de l'industrie chinoise des bases de données a été publié en juin. Le vent intelligent se lève, les colonnes se régénèrent
'coach, I want to play basketball!'—— AI Learning Series booklet for system students
[QNX Hypervisor 2.2用户手册]6.1 使用QNX Hypervisor系统
Basic process of code scanning login
Redis学习笔记—数据类型:字符串(string)
线性表(LinkList)的链式表示和实现----线性结构
社区文章|MOSN 构建 Subset 优化思路分享
670. Maximum Swap
设CPU有16根地址线,8根数据线,并用MREQ作为访存控制线号......存储器与CPU的连接
[advanced Android] kotlin notes
【云原生 | Kubernetes篇】Kubernetes原理与安装(二)
438. Find All Anagrams in a String
Community article | mosn building subset optimization ideas sharing
The sliding window of the force button "step by step" (209. sub array with the smallest length, 904. fruit basket)
S5P4418裸机编程的实现(替换2ndboot)
Custom tag - JSP tag Foundation
[qnx hypervisor 2.2 user manual]6.1 using the QNX hypervisor system
The results of CDN node and source station are inconsistent