Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1-homework-yanjun
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bonnieyan
1-homework-yanjun
Commits
b11e07ee
Commit
b11e07ee
authored
Jan 19, 2019
by
bonnieyan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交作业
parent
597c7e71
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
10 deletions
+21
-10
6-homework-yanjun/heaters.py
+21
-10
No files found.
6-homework-yanjun/heaters.py
View file @
b11e07ee
#
#
# class Solution(object):
#
# def find_radius(self, house, heaters):
#
#
#
# su = Solution()
# su.find_radius([1, 2, 3, 4], [1, 4])
class
Heater
:
def
findRadius
(
self
,
houses
,
heaters
):
heaters
.
sort
()
houses
.
sort
()
radius
=
0
i
=
0
# 哨兵
heaters
=
[
-
1
]
+
heaters
+
[
float
(
'inf'
)]
for
house
in
houses
:
while
house
>
heaters
[
i
]:
i
=
i
+
1
current_radius
=
min
(
house
-
heaters
[
i
-
1
],
heaters
[
i
]
-
house
)
radius
=
max
(
radius
,
current_radius
)
return
radius
h
=
Heater
()
result
=
h
.
findRadius
([
1
,
2
,
3
,
4
,
6
],
[
1
,
4
])
print
(
result
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment