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) 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.

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 更新越来越快了,感觉要成为第一大题库了,赞一个

最新文章

  1. effective java 读后感
  2. 迭代器模式的一种应用场景以及C#对于迭代器的内置支持
  3. wpf 保存控件中的内容为图片格式
  4. angularJS中的$apply(),$digest(),$watch()
  5. 2D Tookit (一) 精灵切割
  6. 安装VS2008无法更改安装路径解决方法
  7. 解决 Cocos2d-x 中 Android.mk 手动添加源文件
  8. 转载: ABAP动态内表操作
  9. Unity4向上(Unity5)兼容PlayerPrefs的数据存储
  10. linux 备份日志文件
  11. XtraReport交叉表隐藏列标题及自定义排序
  12. MySQL中char、varchar和text的区别
  13. 关于毕设WiFi选型
  14. Win手机安卓程序初体验
  15. log4j配置示例
  16. iOS开发基础之设置状态栏和二维码的unspported type found 问题
  17. 【爆料】-《卧龙岗大学毕业证书》UOW一模一样原件
  18. Git开发工作流
  19. 【福州活动】| "福州首届.NET开源社区线下技术交流会"(2018.11.10)
  20. com.borland.jbcl.layout.*;(XYLayout)

热门文章

  1. SQL Server 判断各种对象是否存在和sysobjects的关系
  2. java截取字符串中的最后几个字符
  3. 关于 Paket
  4. 在Visual Studio 2019中开启预览功能
  5. Winform中使用FastReport的PictureObject时通过代码设置图片源并使Image图片旋转90度
  6. 百度地图分布图(百度地图api司机位置实时定位分布图)
  7. HighChat动态绑定数据 数据后台绑定(四)
  8. CSS函数大全
  9. python3类和实例
  10. Android中获取实时网速(2)