Solved LeetCode program · 643 of 1,000
#0872 · Leaf-Similar Trees
Original English source
Keep a shared values holding 3, 5, 1, 6, 2, 9, 8, -1, -1, 7, and 4. Keep a shared lefts holding 1, 3, 5, -1, 9, -1, -1, -1, -1, -1, and -1. Keep a shared rights holding 2, 4, 6, -1, 10, -1, -1, -1, -1, -1, and -1. Keep a shared secondvalues holding 3, 5, 1, 6, 7, 4, 2, -1, -1, -1, -1, -1, -1, 9, and 8. Keep a shared secondlefts holding 1, 3, 5, -1, -1, -1, 13, -1, -1, -1, -1, -1, -1, -1, and -1. Keep a shared secondrights holding 2, 4, 6, -1, -1, -1, 14, -1, -1, -1, -1, -1, -1, -1, and -1. Keep a shared firstleaves as an empty list of whole numbers. Keep a shared otherleaves as an empty list of whole numbers.
To gather first from node (a whole number). If node is less than 0, return. If item node of lefts is less than 0 and item node of rights is less than 0, Place item node of values into firstleaves, return. Gather first from item node of lefts. Gather first from item node of rights.
To gather other from node (a whole number). If node is less than 0, return. If item node of secondlefts is less than 0 and item node of secondrights is less than 0, Place item node of secondvalues into otherleaves, return. Gather other from item node of secondlefts. Gather other from item node of secondrights.
Gather first from 0. Gather other from 0. The same is 1. The firstcount is the number of items in firstleaves. The othercount is the number of items in otherleaves. If firstcount is not othercount, set same to 0.
For every spot from 0 to the last position of firstleaves.
If item spot of firstleaves is not item spot of otherleaves, set same to 0.
If same is 1, show true, otherwise show false.
Expected stdout
true