func flipAndInvertImage(_ A: [[Int]]) -> [[Int]] {
var A = A
for i in stride(from: 0, to: A.count, by: 1) {
var left = 0
var right = A[i].count - 1
while left < right {
A[i].swapAt(left, right)
A[i][left] ^= 1
A[i][right] ^= 1
left += 1
right -= 1
}
if left == right {
A[i][left] ^= 1
}
}
return A
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme