Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- func runningSum(_ nums: [Int]) -> [Int] {
- var pre = [Int]()
- let n = nums.count
- var sum = 0
- for i in nums {
- sum += i
- pre.append(sum)
- }
- return pre
- }
- }
Advertisement
Comments
-
- public extension Collection {
- func inits<T>(_ transform: (SubSequence) throws -> T) rethrows -> [T] {
- try (0...count).map { try transform(prefix($0)) }
- }
- func inits() -> [SubSequence] {
- inits { $0 }
- }
- }
- print([1, 7, 14, 9, 11].inits { $0.reduce(0, +) })
Add Comment
Please, Sign In to add comment
Advertisement