✅ [Swift] Two loops, 100% speed , easy to understand
\n\n\nclass Solution {\n    func largestLocal(_ grid: [[Int]]) -> [[Int]] {\n        var size = grid.count - 2\n\t    var result = Array(repeating: Array(repeat
![image.png](https://assets.leetcode.com/users/images/4cb2cb57-1d4d-49d2-8f32-fdf232c38a2b_1669502945.7273912.png)\n\n```\nclass Solution {\n    func largestLocal(_ grid: [[Int]]) -> [[Int]] {\n        var size = grid.count - 2\n\t    var result = Array(repeating: Array(repeating: 0, count: size), count: size)\n\n\t    for i in 0..<size {\n\t\t    for j in 0..<size {\n\t\t\t    var maxLocal = max(grid[i][j], grid[i][j + 1], grid[i][j + 2])\n\t\t\t    maxLocal = max(maxLocal, grid[i + 1][j], grid[i + 1][j + 1], grid[i + 1][j + 2])\n\t\t\t    maxLocal = max(maxLocal, grid[i + 2][j], grid[i + 2][j + 1], grid[i + 2][j + 2])\n\t\t\t    result[i][j] = maxLocal\n\t\t    }\n\t    }\n\t    return result\n    }\n}\n```
['Swift']