题目描述:

自己的提交:

# """
# This is Sea's API interface.
# You should not implement it, or speculate about its implementation
# """
#class Sea(object):
# def hasShips(self, topRight: 'Point', bottomLeft: 'Point') -> bool:
#
#class Point(object):
# def __init__(self, x: int, y: int):
# self.x = x
# self.y = y class Solution(object):
def countShips(self, sea: 'Sea', topRight: 'Point', bottomLeft: 'Point') -> int:
if topRight.x == bottomLeft.x and topRight.y == bottomLeft.y and sea.hasShips(topRight,bottomLeft):
return 1
if sea.hasShips(topRight,bottomLeft):
mid_h = (topRight.y + bottomLeft.y)//2
mid_w = (topRight.x + bottomLeft.x)//2
a = self.countShips(sea,Point(mid_w,topRight.y),Point(bottomLeft.x,mid_h+1)) if mid_h != topRight.y else 0
b = self.countShips(sea,topRight,Point(mid_w+1,mid_h+1)) if mid_h != topRight.y and mid_w != topRight.x else 0
c = self.countShips(sea,Point(mid_w,mid_h),bottomLeft)
d = self.countShips(sea,Point(topRight.x,mid_h),Point(mid_w+1,bottomLeft.y)) if mid_w != topRight.x else 0
return a + b + c + d
return 0

最新文章

  1. 【iOS开发】在 App 中加入 AdMob 广告 - 入门介绍与编程技巧
  2. MyBatis学习总结(四)——解决字段名与实体类属性名不相同的冲突
  3. Redis集合-Set
  4. 浅析配置更快的Eclipse方法
  5. mysql无法远程连接的解决方法
  6. Unity 全面理解加载和内存管理
  7. php之curl实现http与https请求的方法
  8. mongo常用命令
  9. TFS服务器(微软源代码管理服务器)上彻底删除项目
  10. NSObject中的isa到底是个什么?
  11. git在windows常用命令
  12. Snail—ORACLE基础之事务学习(五)
  13. jquery animate 详解
  14. laravel 简单的上传图片
  15. Spring-Data-JPA整合MySQL和配置
  16. 【机器学习】--xgboost初始之代码实现分类
  17. Linux服务器初步配置流程
  18. 6-2 铁轨 uva 514
  19. elastastic search
  20. all index range ref eq_ref const system 索引type说明

热门文章

  1. threeJS射线拾取机制及案例
  2. 英语单词custom
  3. PHP curl_multi_close函数
  4. 圆周率Pi是如何计算出来的
  5. Apache搭建http网站服务器入门教程
  6. VSphere随笔 - vCenter6.5安装配置手册
  7. vue搭建项目步骤(二)
  8. Cocos2d-x之物理引擎
  9. spring cloud学习--eureka 01
  10. vue 中router.go;router.push和router.replace的区别