Good Solution!

public class Solution {
public int maxKilledEnemies(char[][] grid) {
if(grid==null||grid.length<1) return 0;
int[][] count=new int[grid.length][grid[0].length];
for(int i=0;i<grid.length;i++){
int current=0;
for(int j=0;j<grid[0].length;j++){
current=check(grid,count,i,j,current);
}
}
for(int i=0;i<grid.length;i++){
int current=0;
for(int j=grid[0].length-1;j>=0;j--){
current=check(grid,count,i,j,current);
}
}
for(int j=0;j<grid[0].length;j++){
int current=0;
for(int i=0;i<grid.length;i++){
current=check(grid,count,i,j,current);
}
}
int max=0;
for(int j=0;j<grid[0].length;j++){
int current=0;
for(int i=grid.length-1;i>=0;i--){
current=check(grid,count,i,j,current);
if(grid[i][j]=='0'){
max=Math.max(max,count[i][j]);
}
}
}
return max;
}
public int check(char[][] grid,int[][] count,int i,int j,int current){
if(grid[i][j]=='W'){
return 0;
}else if(grid[i][j]=='E'){
current++;
return current;
}else{//'0'
count[i][j]+=current;
return current;
}
}
}