Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int maxKilledEnemies(vector<vector<char>>& grid) {
- int rows = grid.size(), cols = grid[0].size();
- int ans = 0, rowCount=0;
- vector<int> colCount(cols, 0);
- for(int row=0; row<rows; row++){
- for(int col=0; col<cols; col++){
- if(col == 0 || grid[row][col-1] == 'W'){
- rowCount = 0;
- for(int k=col; k<cols; k++){
- if(grid[row][k] == 'W')
- break;
- else if(grid[row][k] == 'E')
- rowCount += 1;
- }
- }
- if(row == 0 || grid[row-1][col] == 'W'){
- colCount[col] = 0;
- for(int k=row; k<rows; k++){
- if(grid[k][col] == 'W')
- break;
- else if(grid[k][col] == 'E')
- colCount[col] += 1;
- }
- }
- if(grid[row][col] == '0')
- ans = max(ans, rowCount+colCount[col]);
- }
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement