[LeetCode] 419. Battleships in a Board 平板上的战船
2024-10-20 03:58:47
Given an 2D board, count how many 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 shape
1xN
(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
In the above board there are 2 battleships.
Invalid Example:
...X
XXXX
...X
This is an invalid board that you will not receive - as battleships will always have a cell separating between them.
Follow up:
Could you do it in one-pass, using only O(1) extra memory and without modifying the value of the board?
这道题好像之前在地里面见过,忘了是哪家公司的面试题了,现在被 LeetCode 收录了,感觉现在 LeetCode 更新越来越快了,感觉要成为第一大题库了,赞一个
最新文章
- effective java 读后感
- 迭代器模式的一种应用场景以及C#对于迭代器的内置支持
- wpf 保存控件中的内容为图片格式
- angularJS中的$apply(),$digest(),$watch()
- 2D Tookit (一) 精灵切割
- 安装VS2008无法更改安装路径解决方法
- 解决 Cocos2d-x 中 Android.mk 手动添加源文件
- 转载: ABAP动态内表操作
- Unity4向上(Unity5)兼容PlayerPrefs的数据存储
- linux 备份日志文件
- XtraReport交叉表隐藏列标题及自定义排序
- MySQL中char、varchar和text的区别
- 关于毕设WiFi选型
- Win手机安卓程序初体验
- log4j配置示例
- iOS开发基础之设置状态栏和二维码的unspported type found 问题
- 【爆料】-《卧龙岗大学毕业证书》UOW一模一样原件
- Git开发工作流
- 【福州活动】| ";福州首届.NET开源社区线下技术交流会";(2018.11.10)
- com.borland.jbcl.layout.*;(XYLayout)