相关疑难解决方法(0)

快速最大连续正数

如何使用闭包计算最大连续正数?

var numbers = [1,3,4,-1,-2,5,2,-2,-3,-4,5]
//in this case it should be 3

print(numbers.reduce(0, { $1 > 0 ? $0 + 1 : $0 } ))//this counts total positive numbers
Run Code Online (Sandbox Code Playgroud)

closures swift

4
推荐指数
1
解决办法
470
查看次数

标签 统计

closures ×1

swift ×1