Solved LeetCode program · 95 of 1,000
#0095 · Unique Binary Search Trees II
Original English source
Keep a shared used as an empty list of whole numbers. Keep a shared prefix as empty text. Keep a shared answers as an empty list of text. Keep a shared copy as empty text.
To check permutation. The root is the digit value of character 0 of prefix. The second is the digit value of character 1 of prefix. The third is the digit value of character 2 of prefix. The okay is 1. If second is more than root and third is less than root, set okay to 0. If okay is 1, Set copy to a copy of prefix, Place copy into answers.
To permute from depth (a whole number). If depth is 3, check permutation, then return.
For every value from 1 to 3.
If used contains value, skip to the next one. Place value into used. Place the character for value into prefix. Permute from depth plus 1. Remove the last item from used. Remove last character from prefix.
Permute from 0. Report the length of answers. For each answer in answers, report answer.
Expected stdout
5 123 132 213 312 321