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
- Hypothèse concernant la discrimination des numerosites chez les non primates : variation inter espèces, importance relative des infos numériques par rapport aux quantités continues varie selon les espèces
- Si un point M appartient à la médiatrice d'un segment [AB], cela signifie que
- la position limite de la sécante ( AM ) où M est un point de Cf, lorsque M se rapproche de A est appelée la tangente à la courbe Cf au point A de Cf d'abscisse a