FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PythonAlgorithms/array/missing_ranges.py at master · taoran92/PythonAlgorithms · GitHub
taoran92
/
PythonAlgorithms
Public
forked from
keon/algorithms
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
PythonAlgorithms
/
array
/
missing_ranges.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
23 lines (16 loc) · 414 Bytes
Breadcrumbs
PythonAlgorithms
/
array
/
missing_ranges.py
Copy path
File metadata and controls
23 lines (16 loc) · 414 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
Find missing ranges between low and high in the given array.
Ex) [3, 5] lo=1 hi=10 => answer: [(1, 2), (4, 4), (6, 10)]
"""
def
missing_ranges
(
arr
,
lo
,
hi
):
res
=
[]
start
=
lo
for
n
in
arr
:
if
n
==
start
:
start
+=
1
elif
n
>
start
:
res
.
append
((
start
,
n
-
1
))
start
=
n
+
1
if
start
<=
hi
:
res
.
append
((
start
,
hi
))
return
res
Back
|
FazBrowse Home
|
New Git URL