zoukankan      html  css  js  c++  java
  • leetcode1272

     1 class Solution:
     2     def removeInterval(self, intervals: List[List[int]], toBeRemoved: List[int]) -> List[List[int]]:
     3         n = len(intervals)
     4         res = []
     5         for i in range(n):
     6             curent = intervals[i]
     7             if curent[1] <= toBeRemoved[0] or curent[0] >= toBeRemoved[1]:
     8                 res.append(curent)
     9             elif curent[0] >= toBeRemoved[0] and curent[1] <= toBeRemoved[1]:
    10                 continue
    11             elif curent[0] <= toBeRemoved[0] and curent[1] >= toBeRemoved[1]:
    12                 if curent[0] != toBeRemoved[0]:
    13                     res.append([curent[0],toBeRemoved[0]])
    14                 if toBeRemoved[1] != curent[1]:
    15                     res.append([toBeRemoved[1],curent[1]])
    16             elif curent[0] <= toBeRemoved[0] and curent[1] >= toBeRemoved[0] and curent[1] <= toBeRemoved[1]:
    17                 if curent[0] != toBeRemoved[0]:
    18                     res.append([curent[0],toBeRemoved[0]])
    19             elif curent[1] >= toBeRemoved[1] and curent[0] <= toBeRemoved[1] and curent[0] >= toBeRemoved[0]:
    20                 if toBeRemoved[1] != curent[1]:
    21                     res.append([toBeRemoved[1],curent[1]])
    22         return res

    分6种情况讨论(第一个if语句是两种情况)

  • 相关阅读:
    Windows网络编程经验小结
    异步Socket服务器与客户端
    用C#实现C/S模式下软件自动在线升级
    Linux 安装字体
    word 生成目录
    Linux sar使用
    yum 使用说明
    HASH JOIN算法
    row cache lock
    cursor: pin S
  • 原文地址:https://www.cnblogs.com/asenyang/p/11965148.html
Copyright © 2011-2022 走看看