You are viewing a single comment's thread. Return to all comments →
Thanks for the enlightenment.
Here is the same solution in Swift:
func arrayManipulation(n: Int, queries: [[Int]]) -> Int { var numbers = Array(repeating: 0, count: n + 1) var ans = 0 for i in 0 ..< queries.count { var a = queries[i][0] var b1 = queries[i][1] + 1 var k = queries[i][2] numbers[a] += k if b1 <= n { numbers[b1] -= k } } for i in 1...n { numbers[i] += numbers[i - 1] if numbers[i] > ans { ans = numbers[i] } } return ans }
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
Thanks for the enlightenment.
Here is the same solution in Swift: