[Python] Simple code beats 100% in runtime with explanations
Note: \nThe difficult part is to calculate 1000!\nThis solution is not the best one, but is very easy to come up with.\nIt is not good because number gets very 
Note: \nThe difficult part is to calculate 1000!\nThis solution is not the best one, but is very easy to come up with.\nIt is not good because number gets very large as the number of nodes gets bigger.\nIdeally, we should use modular calculations.\n\nUsing pascal\'s triangle\uFF08\u6768\u8F89\u4E09\u89D2\uFF09to calculate all combinations is a better solution.\nBut my version is very simple, so I shared it.\nIf people are interested, go check other solutions for building a tree / using pascal\'s triangle as well.\n\n\t### Precalculation of 0! to 1000! so that we don\'t need to calculate them each time\n\tfacall = [1]\n\tp = 10**9 + 7\n\tresult = 1\n\tfor i in range(1, 1001):\n\t\tresult = (result * i)\n\t\tfacall.append(result)\n\n\tclass Solution:\n\t\tdef numOfWays(self, nums: List[int]) -> int:\n\t\t\tmod = 10**9 + 7\n\n\t\t\tdef helper(nums):\n\t\t\t\t# base case of no node or 1 node\n\t\t\t\tif len(nums) <= 1: return 1\n\n\t\t\t\troot = nums[0]\n\t\t\t\t# find how many numbers are in the left and right subtree\n\t\t\t\tnumsleft = []\n\t\t\t\tnumsright = []\n\t\t\t\tfor n in nums[1:]:\n\t\t\t\t\tif n < root:\n\t\t\t\t\t\tnumsleft.append(n)\n\t\t\t\t\telse:\n\t\t\t\t\t\tnumsright.append(n)\n\n\t\t\t\tleft = helper(numsleft)\n\t\t\t\tright = helper(numsright)\n\t\t\t\t\n\t\t\t\t# for each order of numsleft and numsright\n\t\t\t\t# each time, we can randomly choose one node from numsleft or nums right\n\t\t\t\t# so it is choose len(numsleft) from (len(numsleft) + len(numsright))\n\t\t\t\t# there are left * right combinations\n\t\t\t\treturn (left * right * facall[len(nums)-1] // facall[len(numsleft)] // facall[len(numsright)])%mod\n\t\t\t\n\t\t\t# subtract 1 here because the current order should not be counted.\n\t\t\treturn (helper(nums)-1)%mod
[]