题目描述:

自己的提交:

# """
# 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

leetcode-第14周双周赛-1274-矩形内船只的数目的更多相关文章

  1. LeetCode 第 14 场双周赛

    基础的 api 还是不够熟悉啊 5112. 十六进制魔术数字 class Solution { public: char *lltoa(long long num, char *str, int ra ...

  2. LeetCode第8场双周赛(Java)

    这次我只做对一题. 原因是题目返回值类型有误,写的是 String[] ,实际上应该返回 List<String> . 好吧,只能自认倒霉.就当涨涨经验. 5068. 前后拼接 解题思路 ...

  3. Java实现 LeetCode第30场双周赛 (题号5177,5445,5446,5447)

    这套题不算难,但是因为是昨天晚上太晚了,好久没有大晚上写过代码了,有点不适应,今天上午一看还是挺简单的 5177. 转变日期格式   给你一个字符串 date ,它的格式为 Day Month Yea ...

  4. LeetCode 第 15 场双周赛

    1287.有序数组中出现次数超过25%的元素 1288.删除被覆盖区间 1286.字母组合迭代器 1289.下降路径最小和 II 下降和不能只保留原数组中最小的两个,hacked. 1287.有序数组 ...

  5. leetcode-第14周双周赛-1273-删除树节点

    题目描述: 自己的提交:动态规划 class Solution: def deleteTreeNodes(self, nodes: int, parent: List[int], value: Lis ...

  6. leetcode-第14周双周赛-1272-删除区间

    题目描述: 自己的提交: class Solution: def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[ ...

  7. leetcode-第14周双周赛-1271-十六进制魔术数字

    自己的提交: class Solution: def toHexspeak(self, num: str) -> str: num = hex(int(num)) num = str(num)[ ...

  8. leetcode-第12周双周赛-5111-分享巧克力

    题目描述: 方法: class Solution: def maximizeSweetness(self, A: List[int], K: int) -> int: def possible( ...

  9. leetcode-12周双周赛-5090-抛掷硬币

    题目描述: 二维dp: class Solution: def probabilityOfHeads(self, prob: List[float], target: int) -> float ...

随机推荐

  1. 英语单词profile

    profile 来源——linux系统文件名 [root@centos71 ~]# cat /etc/profile # /etc/profile # System wide environment ...

  2. myeclipse svn重新定位 本地文件 svn 重新定位

    我们在用工具myeclipse开发项目时,当资源库存储空间不够时,我们就需要添加资源库,涉及到我们切换项目资源库,下面就介绍一下svn资源库重新定位步骤 1,window到show view到othe ...

  3. kNN#约会网站预测数据

    #约会网站预测数据 def classifyPersion(): resultList = ['not at all','in small doses','in large doses'] #inpu ...

  4. php获取linux服务器CPU、内存、硬盘使用率的实现代码

    define("MONITORED_IP", "172.16.0.191"); //被监控的服务器IP地址 也就是本机地址 define("DB_SE ...

  5. 【靶场练习_sqli-labs】SQLi-LABS Page-4 (Challenges)

    Less-54: ?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where tabl ...

  6. socket | netcat 模拟

    #!/opt/local/bin/python2.7 #coding=utf-8 ''' 取代netcat 两台主机中其中一台控制另一台 得到北控方的shell ''' import sys impo ...

  7. 前端每日实战:18# 视频演示如何用纯 CSS 创作 404 文字变形为 NON 文字的交互特效

    效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/ZoxjXm 可交互视频教程 此视频 ...

  8. (转)Windows下zookeeper安装及配置

    转:https://blog.csdn.net/qq_36332827/article/details/79700239 zookeeper有单机.伪集群.集群三种部署方式,可根据自己对可靠性的需求选 ...

  9. 信息安全-OAuth2.0:NuGetFromMicrosoft

    ylbtech-信息安全-OAuth2.0:NuGetFromMicrosoft 1.返回顶部 1. https://login.microsoftonline.com/common/oauth2/v ...

  10. The 13th Chinese Northeast Collegiate Programming Contest(B C E F H J)

    B. Balanced Diet 思路:把每一块选C个产生的价值记录下来,然后从小到大枚举C. #include<bits/stdc++.h> using namespace std; ; ...