My Swift Solution
Refer to the solution.\n\nclass Solution {\n    func bestRotation(_ nums: [Int]) -> Int {\n        var scoreTrend = Array(repeating: 0, count: nums.count)\n    
Refer to the solution.\n```\nclass Solution {\n    func bestRotation(_ nums: [Int]) -> Int {\n        var scoreTrend = Array(repeating: 0, count: nums.count)\n        var bestScore = 0\n        var currentScore = 0\n        let n = nums.count\n        var shift = 0\n        \n        for (i, num) in nums.enumerated() {\n            if num > i {\n                scoreTrend[i+1] += 1\n                let a = (n-num+i+1)%n\n                if a != 0 {\n                    scoreTrend[(n-num+i+1)%n] -= 1\n                }\n            }\n            else {\n                if i != n-1 {\n                    scoreTrend[i+1] += 1\n                }\n                scoreTrend[0] += 1\n                scoreTrend[(i-num+1)%n] -= 1\n            }\n        }\n\n        for (i, step) in scoreTrend.enumerated() {\n            currentScore += step\n            if currentScore > bestScore {\n                bestScore = currentScore\n                shift = i\n            }\n            \n        }\n        return shift\n    }\n}\n```
['Swift']