In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "Java how to judge whether an array is a post-order traversal result". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn "Java how to determine whether an array is a post-order traversal result"!
Enter an array of integers to determine whether the array is the result of a post-traversal of a binary search tree. If true is returned, otherwise false is returned.
Idea 1:
The middle order is traversed as a growth array to determine whether it is contradictory or not.
Idea 2:
Such as 5, 7, 6, 9, 11, 10, 8
Specific ideas for writing code:
1. Find the first number greater than the root node, that is, 9, so the one after 9 is the right subtree.
two。 If the value of the right subtree is greater than the root node 8, the
3. The recursive method is used to determine whether the left subtree and the right subtree are in line with this characteristic.
Package com.lifeibigdata.algorithms.blog;import java.util.Arrays;/** 5, 7, 6, 9, 11, 10, 8 * 8 /\ 6 10 /\ 5 7 9 11 * / public class SearchTree {public static void main (String [] args) {/ / int [] a = {5, 7, 6, 9, 10}; / / true int a [] = {7,4,6,5} / / false System.out.println (searchTree (amema.length));} static boolean searchTree (int [] apenint length) {if (a = = null | | length 0) {searchTree (apeny I);} if (I < length-1) {searchTree (Arrays.copyOfRange (adint length-1), length-I-1);} return flag }} at this point, I believe you have a deeper understanding of "how Java determines whether an array is a post-order traversal result". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.