Swift solution
Swift solution\n\nclass Solution {\n    func sumOfBeauties(_ nums: [Int]) -> Int {\n        let n = nums.count\n        guard n > 2 else { return 0 }\n        v
Swift solution\n```\nclass Solution {\n    func sumOfBeauties(_ nums: [Int]) -> Int {\n        let n = nums.count\n        guard n > 2 else { return 0 }\n        var preMax = nums, postMin = nums, result = 0\n        for i in 1..<n {\n            preMax[i] = max(preMax[i], preMax[i - 1])\n            postMin[n - 1 - i] = min(postMin[n - 1 - i], postMin[n - i])\n        }\n        for i in 1..<(n - 1) {\n            if nums[i] > preMax[i - 1] && nums[i] < postMin[i + 1] {\n                result += 2\n            } else if nums[i] > nums[i - 1] && nums[i] < nums[i + 1] {\n                result += 1\n            }\n        }\n        return result\n    }\n}\n```
['Swift']