Last active
March 27, 2024 20:57
-
-
Save ubranch/0ad142669adb4d381206f225466da06b to your computer and use it in GitHub Desktop.
This file contains 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
class Solution: | |
def maxWidthOfVerticalArea(self, points: List[List[int]]) -> int: | |
# O(n log n) | |
points.sort() # X koordinata bo'yicha sort qb olamiz (sort doim birinchi item bo'yicha sortlab oladi, bizni holatimizda bu [X,Y] dan X) | |
max_width = 0 # Natija | |
for i in range(len(points) - 1): | |
# Hozirgi va bitta oldingi X koordinatalar o'rtasidagi farqni topib olamiz | |
diff_width = points[i][0] - points[i - 1][0] | |
# Natijani qaisi biri kattaligiga qarab belgilab olamz | |
max_width = max(max_width, diff_width) | |
return max_width | |
# O(n log n) | |
x_coords = sorted(point[0] for point in points) # faqat X kordinata bo'yicha sortlab olamiz (shu uchun saal tezroq) | |
return max(x_coords[i] - x_coords[i - 1] for i in range(1, len(x_coords))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment