将2D数组中的某些行置零

时间:2019-04-04 04:04:37

标签: swift

有没有办法以一行代码或更短的形式制作这些循环?

var matrix : [[Int]] = [
  [0,1,2,9],
  [3,4,5,2],
  [1,3,1,5]
]

for i in rowIndexes
{ 
  for c in 0..<nCol
  {
      matrix[i][c] = 0
  }
}

output : [[Int]] = [
  [0,0,0,0],
  [3,4,5,2],
  [1,3,1,5]
 ]

0 个答案:

没有答案