✅ [Solution] Swift: Candy (+ test cases)
swift\nclass Solution {\n    func candy(_ ratings: [Int]) -> Int {\n        let len = ratings.count\n        guard len > 1 else { return len }\n        \n      
```swift\nclass Solution {\n    func candy(_ ratings: [Int]) -> Int {\n        let len = ratings.count\n        guard len > 1 else { return len }\n        \n        var value = 0\n        \n        var lhs2rhs = [Int](repeating: 1, count: len)\n        var rhs2lhs = [Int](repeating: 1, count: len)\n        \n        for i in 1..<len where ratings[i] > ratings[i - 1] {\n            lhs2rhs[i] = lhs2rhs[i - 1] + 1\n        }\n        for i in (0..<(len - 1)).reversed() where ratings[i] > ratings[i + 1] {\n            rhs2lhs[i] = rhs2lhs[ i + 1] + 1\n        }\n        for i in 0..<len {\n            value += max(lhs2rhs[i], rhs2lhs[i])\n        }\n        return value\n    }\n}\n```\n\n---\n\n<p>\n<details>\n<summary>\n<img src="https://git.io/JDblm" height="24">\n<b>TEST CASES</b>\n</summary>\n\n<p><pre>\n<b>Result:</b> Executed 2 tests, with 0 failures (0 unexpected) in 0.010 (0.012) seconds\n</pre></p>\n\n```swift\nimport XCTest\n\nclass Tests: XCTestCase {\n    \n    private let solution = Solution()\n    \n    // You can allocate to the first, second and third child with 2, 1, 2 candies respectively.\n    func test0() {\n        let value = solution.candy([1,0,2])\n        XCTAssertEqual(value, 5)\n    }\n    \n    // You can allocate to the first, second and third child with 1, 2, 1 candies respectively.\n    // The third child gets 1 candy because it satisfies the above two conditions.\n    func test1() {\n        let value = solution.candy([1,2,2])\n        XCTAssertEqual(value, 4)\n    }\n}\n\nTests.defaultTestSuite.run()\n```\n\n</details>\n</p>
['Swift']