File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 1- # Approach 1 : Linear Scan
1+ # Approach: Linear Scan
22
33# Time: O(n)
44# Space: O(1)
@@ -7,19 +7,24 @@ class Solution:
77 def findMissingRanges (self , nums : List [int ], lower : int , upper : int ) -> List [List [int ]]:
88 n = len (nums )
99 missing_ranges = []
10+
1011 if n == 0 :
1112 missing_ranges .append ([lower , upper ])
1213 return missing_ranges
1314
15+ # Check for any missing numbers between the lower bound and nums[0]
1416 if lower < nums [0 ]:
1517 missing_ranges .append ([lower , nums [0 ] - 1 ])
1618
19+ # Check for any missing numbers between successive elements of nums
1720 for i in range (n - 1 ):
1821 if nums [i + 1 ] - nums [i ] <= 1 :
1922 continue
2023 missing_ranges .append ([nums [i ] + 1 , nums [i + 1 ] - 1 ])
2124
25+ # Check for any missing numbers between the last element of nums and the upper bound
2226 if upper > nums [n - 1 ]:
2327 missing_ranges .append ([nums [n - 1 ] + 1 , upper ])
2428
2529 return missing_ranges
30+
You can’t perform that action at this time.
0 commit comments