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

Commitc654d01

Browse files
refactor 531
1 parentefe62ea commitc654d01

File tree

1 file changed

+28
-26
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+28
-26
lines changed
Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
packagecom.fishercoder.solutions;
22

33
/**
4+
* 531. Lonely Pixel I
5+
*
46
* Given a picture consisting of black and white pixels, find the number of black lonely pixels.
5-
6-
The picture is represented by a 2D char array consisting of 'B' and 'W', which means black and white pixels respectively.
7-
8-
A black lonely pixel is character 'B' that located at a specific position where the same row and same column don't have any other black pixels.
7+
* The picture is represented by a 2D char array consisting of 'B' and 'W', which means black and white pixels respectively.
8+
* A black lonely pixel is character 'B' that located at a specific position where the same row and same column don't have any other black pixels.
99
1010
Example:
1111
Input:
@@ -15,42 +15,44 @@
1515
1616
Output: 3
1717
Explanation: All the three 'B's are black lonely pixels.
18+
1819
Note:
1920
The range of width and height of the input 2D array is [1,500].
2021
*/
2122
publicclass_531 {
2223

23-
publicintfindLonelyPixel(char[][]picture) {
24-
intm =picture.length;
25-
intn =picture[0].length;
26-
intcount =0;
27-
for (inti =0;i <m;i++) {
28-
for (intj =0;j <n;j++) {
29-
if (picture[i][j] =='B' &&isLonely(i,j,picture,m,n)) {
30-
count++;
24+
publicstaticclassSolution1 {
25+
publicintfindLonelyPixel(char[][]picture) {
26+
intm =picture.length;
27+
intn =picture[0].length;
28+
intcount =0;
29+
for (inti =0;i <m;i++) {
30+
for (intj =0;j <n;j++) {
31+
if (picture[i][j] =='B' &&isLonely(i,j,picture,m,n)) {
32+
count++;
33+
}
3134
}
3235
}
36+
returncount;
3337
}
34-
returncount;
35-
}
3638

37-
privatebooleanisLonely(introw,intcol,char[][]picture,intm,intn) {
38-
for (inti =0;i <m;i++) {
39-
if (i !=row) {
40-
if (picture[i][col] =='B') {
41-
returnfalse;
39+
privatebooleanisLonely(introw,intcol,char[][]picture,intm,intn) {
40+
for (inti =0;i <m;i++) {
41+
if (i !=row) {
42+
if (picture[i][col] =='B') {
43+
returnfalse;
44+
}
4245
}
4346
}
44-
}
4547

46-
for (intj =0;j <n;j++) {
47-
if (j !=col) {
48-
if (picture[row][j] =='B') {
49-
returnfalse;
48+
for (intj =0;j <n;j++) {
49+
if (j !=col) {
50+
if (picture[row][j] =='B') {
51+
returnfalse;
52+
}
5053
}
5154
}
55+
returntrue;
5256
}
53-
returntrue;
5457
}
55-
5658
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp