Last active
March 9, 2023 02:04
-
-
Save kenchou/e91c98b596927d7abece706c1b7cd50f to your computer and use it in GitHub Desktop.
python 检查范围值是否重叠
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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