From e7b7adce945435fe86fd8e4d942562e304f149e0 Mon Sep 17 00:00:00 2001 From: Soap Date: Mon, 17 Oct 2022 20:36:20 -0700 Subject: [PATCH] Add a solution to Bomb Enemy --- Array/BombEnemy.swift | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Array/BombEnemy.swift diff --git a/Array/BombEnemy.swift b/Array/BombEnemy.swift new file mode 100644 index 0000000..98234e7 --- /dev/null +++ b/Array/BombEnemy.swift @@ -0,0 +1,50 @@ +/** + * Question Link: https://leetcode.com/problems/bomb-enemy/ + * Primary idea: Greedy. Update the result only when there is wall or at the beginning. + * Time Complexity: O(mn), Space Complexity: O(n) + * + */ + +class BombEnemy { + func maxKilledEnemies(_ grid: [[Character]]) -> Int { + let m = grid.count, n = grid[0].count + var res = 0, rowHit = 0, colHit = Array(repeating: 0, count: n) + + for i in 0..