不知道为什么错了。。。eclipse上明明是正确的啊 leetcode上就显示runtime error
大家不吝赐教啊,多谢多谢 >_<
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public TreeNode buildTree(int[] inorder, int[] postorder) { // Start typing your Java solution below // DO NOT write main() function int length = inorder.length; if (length <= 0) return null; int val = postorder[postorder.length-1]; TreeNode tree = new TreeNode(val); int index = Arrays.binarySearch(inorder, val); int[] leftin = (0<index Arrays.copyOfRange(inorder, 0, index); int[] rightin = (index + 1 < length ? Arrays.copyOfRange(inorder, index + 1, length) : null); int templength = leftin.length; int[] leftpost = Arrays.copyOfRange(inorder, 0, templength); int[] rightpost = Arrays.copyOfRange(inorder, templength, length-1); tree.left = buildTree(leftin, leftpost); tree.right = buildTree(rightin, rightpost); return tree; } }
大家不吝赐教啊,多谢多谢 >_<
发表评论
-
Insert Interval
2012-11-11 01:33 541各种条件真复杂,不仅是边界条件,而且还要分很多种情况讨论 而且 ... -
Implement strStr()
2012-11-07 15:44 581唉 终于到了要记算法的时候了 KMP。。。还没写完 回去再写。 ... -
Flatten Binary Tree to Linked List && Generate Parentheses && Gray Code
2012-11-07 00:08 1091Flatten太简单了 递归 一遍过 oh yeah = = ... -
First Missing Positive
2012-11-06 22:50 588唉 想了很久都没想出来 后来还是看了网上的答案 >_&l ... -
Edit Distance
2012-11-06 00:27 669动规 就是递推。。。比较难想 然后数组长度设置比字符串长度多一 ... -
Divide Two Integers
2012-11-05 00:12 712自己实现除法 太太太恶心了。。。。 就是用位移代替了乘法,然后 ... -
Distinct Subsequences
2012-11-04 21:44 657动规,从前到后用T的每一个字符i,扫描S的每一个字符j。维护一 ... -
Count and Say
2012-11-04 18:46 692public class Solution { ... -
Convert Sorted Array to Binary Search Tree && Convert Sorted List to Binary Sear
2012-11-04 17:36 826/** * Definition for binary ... -
Container With Most Water
2012-11-04 00:25 697本来以为是个简单的题目,直接二重循环,结果小测试过了,大测试超 ... -
Combinations
2012-11-03 22:19 604全排列 按理说很简单,可是用递归写,边界条件就还是难想清楚,s ... -
Combination Sum I && II
2012-11-03 21:41 751还是递归 但是边界条件以及边界上的处理不容易搞清楚(一开始我就 ... -
climbing stairs
2012-11-03 17:18 609一开始觉得是简单的组合数学题,但是写完之后发现,首先组合数不是 ... -
Binary Tree Inorder Traversal
2012-11-02 23:51 615I简单 直接递归就好 addAll函数很好用 /** ... -
Best Time to Buy and Sell Stock I & II
2012-11-02 22:05 1044啊 第一次直接过small和big测试 好爽!虽然主要是以前知 ... -
Balanced Binary Tree
2012-11-01 23:38 609/** * Definition for binary ... -
Anagrams
2012-10-31 00:33 586这题实在是没懂它的意思。。。囧啊 import java. ... -
Add Two Numbers
2012-10-30 23:03 614这题不难 直接上递归就行 /** * Definiti ... -
Add Binary
2012-10-29 00:07 599public String addBinary(Strin ... -
4Sum
2012-10-27 22:49 734本来以为只要在3Sum外面再包一层循环就好了,可是。。。在Ju ...
相关推荐
Construct Binary Tree from Inorder and Postorder Traversa.根据先序后续构建二叉树
Construct Binary Tree from Preorder and Inorder Traversal 根据先序,中序建立二叉树
105.construct_binary_tree_from_preorder_and_inorder_traversal从前序
Construct Binary Tree from Inorder and Postorder Traversal 二叉查找树 Unique Binary Search Trees Unique Binary Search Trees II Validate Binary Search Tree Convert Sorted Array to Binary Search Tree ...
421 | [Maximum XOR of Two Numbers in an Array](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/) | [C++](./C++/maximum-xor-of-two-numbers-in-an-array.cpp) [Python](./Python/...
106.construct-binary-tree-from-inorder-and-postorder-traversal (从中序与后序遍历序列构造二叉树) 112.path-sum (路径总和) 116.populating-next-right-pointers-in-each-node (填充每个节点的下一个右侧节点
lru缓存leetcode LeetCode_Note leetcode 个人笔记 ...[106_construct-binary-tree-from-inorder-and-postorder-traversal.cpp] [107_binary-tree-level-order-traversal-ii.cpp] [108_convert-sorted
leetcode 跳跃 Algorithm 算法题解: 包括书籍算法, 程序员算法面试指南, 还有leetcode算法题 ...construct-binary-tree-from-inorder-and-postorder-traversal 无官方题解 116 populating-next-right-pointers-in-eac
Construct Optimal Binary Search Tree by Using Greedy Algorithm
Inorder Traversal 用两个栈实现队列 232. Implement Queue using Stacks 旋转数组的最小数字 153. Find Minimum in Rotated Sorted Array 斐波那契数列 509. Fibonacci Number 跳台阶 70. Climbing Stairs 变态跳...
No prior experience is required.Game Development with Construct 2 teaches you to create 12 different game projects from a variety of genres, including car racing and tower defense to platformer and ...
to construct binary codes for users and items such that the preference of users over items can be accurately preserved by the Hamming distance between their respective binary codes. By using two loss ...
二叉树的实现代码 /*LinkTree.h*/ typedef int DataType; //这样定义意味着节点中能放一个整数,但如果是非叶子节点则可以解读为对应的操作符的ascii ...void inOrder( BinTree t); //travel in order
https://leetcode-cn.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ 2 题目描述 根据一棵树的中序遍历与后序遍历构造二叉树。 注意: 你可以假设树中没有重复的元素。 例如,给出 中序...
concerning 345 burglars and 310 violent offenders in Nottinghamshire, England. The most important observable features of offenders were sex, ethnicity, age, height, build, hair color, hair length, and...
language testing 权威刊物文章 可供语言测试与学习者使用。
The frequency's must be listed, in order, from largest (at the top) to smallest (at the bottom) Then, using the Huffman algorithm, construct the optimal prefix binary code for the table. The Huffman ...
内含大量实例,来自多个知名算法测试平台的题目,还有讲解。
Biomimicry uses our scientific understanding of biological systems to exploit ideas from nature in order to construct some technology. In this book, we focus on how to use biomimicry of the functional...
The methodology used to construct tree structured rules is the focus of this monograph. Unlike many other statistical procedures, which moved from pencil and paper to calculators, this text's use of ...