# Confused with test cases

• ["XXXX","...X","...X"] returns 1
[".X..","XXXX",".X.."] returns 2
what's the rule here?

• Cannot understand the question

• "They can only be made of the shape 1xN (1 row, N columns) or Nx1 (N rows, 1 column), where N can be of any size."

"At least one horizontal or vertical cell separates between two battleships - there are no adjacent battleships."

you are probably talking about a case that violates the input assumption.

• Unless you couple of solutions it is hard to understand the question. I went through this solution and understood what the question is,

public int countBattleships(char[][] board) {
int result = 0;
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[0].length; j++) {
if (board[i][j] == 'X' &&
(i == 0 || board[i - 1][j] == '.') &&
(j == 0 || board[i][j - 1] == '.')) {
result++;
}

``````        }
}
return result;

}``````

• I think this line is the source of all confusion.

``````At least one horizontal or vertical cell separates between two battleships - there are no adjacent battleships.
``````

The start of the sentence says that there is `atleast` one horizontal `or` vertical cell seperation. But then, the statement ends with `"there are no adjacent battleships"`

if you get fixated on the end of the sentence then it is hard to figure out why the example below has 2 battleships.

``````X..X
...X
...X
``````

`Atleast` is the key here. Read it again, then you could understand it better

• @WenboTian You guys shouldn't take those invalid test cases into consideration since the author assumed that all test cases are valid. If there's an invalid test case in LeetCode checker, just ignore it.

• 'XXXX' is invalid example,"At least one horizontal or vertical cell separates between two battleships - there are no adjacent battleships."But I can't alse understand this question.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.