2 Star 2 Fork 1

Justin Yuan/LeetCode-Swift

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
RotateImage.swift 722 Bytes
一键复制 编辑 原始数据 按行查看 历史
/**
* Question Link: https://leetcode.com/problems/rotate-image/
* Primary idea: Go from clockwise and from outside to inside, use offset for convenience
*
* Time Complexity: O(n^2), Space Complexity: O(1)
*/
class RotateImage {
func rotate(_ matrix: inout [[Int]]) {
let n = matrix.count
for layer in 0..<n / 2 {
let start = layer, end = n - layer - 1
for i in start..<end {
let offset = i - start
(matrix[start][i], matrix[i][end], matrix[end][end - offset], matrix[end - offset][start]) = (matrix[end - offset][start], matrix[start][i], matrix[i][end], matrix[end][end - offset])
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/BiggerMax/LeetCode-Swift.git
git@gitee.com:BiggerMax/LeetCode-Swift.git
BiggerMax
LeetCode-Swift
LeetCode-Swift
master

搜索帮助