Solution with Swift

  • 0

    I have implemented this in Swift. The complexity is O(n), but I get a time limit exceeded error on submission. I think it could be a problem with the swift compiler and not the program. Has any one else had a similar issue? Here is the code:

    class Solution {
        func rotate(_ nums: inout [Int], _ k: Int) {
            let rotations = k%nums.count
            var i=0
            while(i<rotations) {
                nums.insert(nums.last!, at: 0)
                i += 1

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.