如何在swift中获取数组中最大元素的个数

如何解决?在这种情况下,我应该得到2。如何在swift中获取数组中最大元素的个数

var r = [1, 3, 5] 

r.max() // gives 5

PS:新的质量standarts时发布 - 是一些疯狂...

回答:

这是我怎么会去这样做:

let array = [1, 3, 5] 

if let (maxIndex, maxValue) = array.enumerated.max{ $0.element < $1.element } {

print("The max element is \(maxValue) at index \(maxIndex)")

}

else {

print("The array is empty, and has no max element or index.")

}

以上是 如何在swift中获取数组中最大元素的个数 的全部内容, 来源链接: utcz.com/qa/257733.html

回到顶部