描述
给一个二维矩阵, 每一个格子都可能是一堵墙 W, 一个敌人 E 或者空 0 (数字 ‘0’), 返回你可以用一个炸弹杀死的最大敌人数. 炸弹会杀死所有在同一行和同一列没有墙阻隔的敌人, 因为墙比较坚固难以摧毁.
你只能在空的地方放置炸弹.
样例
给一个矩阵:
0 E 0 0
E 0 W E
0 E 0 0
返回 3.(在(1, 1)处放炸弹可以杀死 3 个敌人)
思路
分别计算四个方向的杀死敌人的数目,最终返回最大值。
#ifndef C553_H
#define C553_H
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
class Solution {
public:
/**
* @param grid: Given a 2D grid, each cell is either 'W', 'E' or '0'
* @return: an integer, the maximum enemies you can kill using one bomb
*/
int maxKilledEnemies(vector<vector<char>> &grid) {
// write your code here<