Skip to content

Instantly share code, notes, and snippets.

@kenchou
Last active March 9, 2023 02:04
Show Gist options
  • Select an option

  • Save kenchou/e91c98b596927d7abece706c1b7cd50f to your computer and use it in GitHub Desktop.

Select an option

Save kenchou/e91c98b596927d7abece706c1b7cd50f to your computer and use it in GitHub Desktop.
python 检查范围值是否重叠
def check_overlap(ranges):
"""
Check if there is overlap in a list of ranges
"""
sorted_ranges = sorted(ranges, key=lambda x: x[0])
for i in range(len(sorted_ranges) - 1):
if sorted_ranges[i][1] > sorted_ranges[i+1][0]:
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment