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

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


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容