419. Battleships in a Board

given a 2D board, count how many different battleships are in it. The battleships are represented with'X's, empty slots are represented with'.'s. You may assume the following rules:

You receive a valid board, made of only battleships or empty slots.
Battleships can only be placed horizontally or vertically. In other words, they can only be made of the shape1xN(1 row, N columns) orNx1(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.
Example:
X..X
 ...X
 ...X

英语是个问题, 理解不好做题就费劲, 这题说, 军港里有战舰横纵两种方式拜访, 每个军舰大小不一样但彼此之间要有个间隔。 那么也就是说, 如果他的上和左均为 . 可以视为一个新的战舰。 那么输入数组是有效的数组, 所以不必考虑无效的情况。


419. Battleships in a Board_第1张图片

你可能感兴趣的:(419. Battleships in a Board)