Want to know:
和preorder那题相似,只是从后往前遍历的。还是用inorder来的到左边和右边的size,用postorder来的到root public TreeNode build(int[] inorder, int[] postorder, int inStart, int inEnd, int post, HashMap<Integer, Integer> map){ int index = map.get(postorder[post]); int leftSize = index - inStart; int rightSize = inEnd - index; int left = post - rightSize -1; int right = post - 1; TreeNode root = new TreeNode(postorder[post]); if(leftSize > 0) { root.left = build(inorder, postorder, inStart, index-1, left, map); } if(rightSize > 0) { root.right = build(inorder, postorder, index+1, inEnd, right, map); } return root; }
Get a detailed, AI-powered explanation for this question and thousands more on StudyFetch.
Get the Answer for FreeHow StudyFetch Helps You Master This Topic
AI-Powered Answers
Get instant, detailed explanations powered by AI that understands your course material.
Deep Understanding
Go beyond surface-level answers with step-by-step breakdowns and examples.
Personalized Learning
Spark.E adapts to your learning style and helps you connect ideas.
Practice & Test
Turn any question into flashcards, quizzes, and practice tests to solidify your knowledge.
Explore More Questions
- un résultat possible d'une expérience aléatoire.
- Laquelle des affirmations suivantes décrit le mieux une erreur de type II?❑ C'est la probabilité de rejeter une hypothèse nulle alors qu'elle est, en réalité, vraie. ❑ C'est égal à la puissance du test. ❑ C'est équivalent à la taille du test. ❑ C'est la probabilité de ne pas rejeter une hypothèse nulle qui est, en réalité, fausse.
- Si un parralélogramme a une aire de 208 cm^2 et une hauteur de 13 cm, la hauteur est: