Other problems here https://jinblack.com/leetcode-swift/

class Solution {
    func largestRectangleArea(_ heights: [Int]) -> Int {
	    guard !heights.isEmpty else { return 0 }
        var maxA = 0
        var minR = [Int: Int]()
        for (i, h) in heights.enumerated() {
            if let r = minR[h], r >= i {
                continue
            }
            var w = 1, r = i
            for j in 0..<i {
                guard heights[i-1-j] >= heights[i] else { break }
                w += 1
            }
            for j in i+1..<heights.count {
                guard heights[j] >= heights[i] else { break }
                w += 1
                r += 1
            }
            minR[h] = r
            maxA = max(maxA, w*h)
        }
        return maxA
    }
}

Runtime: 1624 ms, faster than 27.87% of Swift online submissions for Largest Rectangle in Histogram.
Memory Usage: 20.1 MB, less than 50.00% of Swift online submissions for Largest Rectangle in Histogram.