https://leetcode.com/problems/unique-binary-search-trees-ii


Success!

___

```python
from itertools import permutations
  
class Solution:
    def generateTrees(self, n: int) -> List[Optional[TreeNode]]:
        #2022/12/30 5:58
        def insert_a_value_to_binary_search_tree(node: Optional[TreeNode], value: int):
            if node == None:
                return TreeNode(value)
            if value > node.val:
                node.right = insert_a_value_to_binary_search_tree(node.right, value)
            elif value < node.val:
                node.left = insert_a_value_to_binary_search_tree(node.left, value)
            return node
            
        def bst_tree_creating(values: List[int], root_node: TreeNode):
            for value in values:
                insert_a_value_to_binary_search_tree(root_node, value)
        
        def get_identity_of_a_tree(node, value_list):
            if node == None:
                return 
            else:
                value_list.append(node.val)
            get_identity_of_a_tree(node.left, value_list)
            get_identity_of_a_tree(node.right, value_list)
        
        values = list(range(1, n+1))
        possible_insert_orders = permutations(values, len(values))
        nodes = []
        id_list = []
        for one in possible_insert_orders:
            root = TreeNode(one[0])
            bst_tree_creating(one[1:], root)

            id = []
            get_identity_of_a_tree(root, id)
            if id not in id_list:
                id_list.append(id.copy())
                nodes.append(root)

        return nodes
        #2022/12/30 6:46
```
