The TransCompilator

Solved LeetCode program · 757 of 1,000

#0993 · Cousins in Binary Tree

Easy Depth-First Search chunk-16.md

Original English source

Keep a shared values holding 1, 2, 3, 4, and 5. Keep a shared lefts holding 1, -1, -1, -1, and -1. Keep a shared rights holding 2, 3, 4, -1, and -1. Keep a shared depths as an empty list of whole numbers. Keep a shared parents as an empty list of whole numbers. For every spot from 0 to 4, Place 0 into depths. For every spot from 0 to 4, Place 0 into parents.

To walk from node (a whole number) with parent (a whole number) and level (a whole number). If node is less than 0, return. Set item node of depths to level. Set item node of parents to parent. Walk from item node of lefts with node and level plus 1. Walk from item node of rights with node and level plus 1.

Walk from 0 with -1 and 0. The first is -1, while the second is -1.
For every spot from 0 to 4.
If item spot of values is 4, set second to spot. If item spot of values is 5, set first to spot.

The verdict is 0. If item first of depths is item second of depths and item first of parents is not item second of parents, set verdict to 1. If verdict is 1, show true, otherwise show false.

Open in Playground Browse all 1,000 problems

Expected stdout

true