Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf62249b

Browse files
authored
Create Bomb Enemy.java
1 parentd75843b commitf62249b

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

‎Medium/Bomb Enemy.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
classSolution {
2+
publicintmaxKilledEnemies(char[][]grid) {
3+
if (grid.length ==0) {
4+
return0;
5+
}
6+
introws =grid.length;
7+
intcols =grid[0].length;
8+
intmaxCount =0;
9+
introwHits =0;
10+
int[]colHits =newint[cols];
11+
for (inti =0;i <rows;i++) {
12+
for (intj =0;j <cols;j++) {
13+
if (j ==0 ||grid[i][j -1] =='W') {
14+
rowHits =0;
15+
for (intk =j;k <cols;k++) {
16+
if (grid[i][k] =='W') {
17+
break;
18+
}
19+
if (grid[i][k] =='E') {
20+
rowHits++;
21+
}
22+
}
23+
}
24+
if (i ==0 ||grid[i -1][j] =='W') {
25+
colHits[j] =0;
26+
for (intk =i;k <rows;k++) {
27+
if (grid[k][j] =='W') {
28+
break;
29+
}
30+
if (grid[k][j] =='E') {
31+
colHits[j]++;
32+
}
33+
}
34+
}
35+
if (grid[i][j] =='0') {
36+
maxCount =Math.max(maxCount,rowHits +colHits[j]);
37+
}
38+
}
39+
}
40+
returnmaxCount;
41+
}
42+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp