[Python3] Beats 100% Solution
python\nclass Solution:\n    def sumOfBeauties(self, nums: List[int]) -> int:\n        n = len(nums)\n        ans = 0\n        maxPre = nums[0]\n        minNums
```python\nclass Solution:\n    def sumOfBeauties(self, nums: List[int]) -> int:\n        n = len(nums)\n        ans = 0\n        maxPre = nums[0]\n        minNums = nums[-1]\n        minPost = [0]*(n-1)\n        for i in range(n-2, 0, -1):\n            minPost[i] = minNums\n            if nums[i] < minNums:\n                minNums = nums[i]\n        for i in range(1, n-1):\n            if nums[i] > maxPre and nums[i] < minPost[i]:\n                ans += 2\n            elif nums[i] > nums[i-1] and nums[i] < nums[i+1]:\n                ans += 1\n            if nums[i] > maxPre:\n                maxPre = nums[i]\n        return ans\n```\n\n![image](https://assets.leetcode.com/users/images/08a03455-cea4-4041-9509-2cd93723ec12_1632024617.4964492.png)\n
['Python3']