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语句是两种情况)

  • 相关阅读:
    idea自带的maven
    面试题汇总
    mybatis参数处理
    tips
    mybatis-config.xml
    helloWorld程序
    idea遇到的问题汇总
    PL/SQL批量执行SQL脚本文件
    Iframe跳转本地项目
    angular video播放问题
  • 原文地址:https://www.cnblogs.com/asenyang/p/11965148.html
Copyright © 2011-2022 走看看