FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/max_sum.py at master · shell-develop/algorithm · GitHub
shell-develop
algorithm
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
max_sum.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
21 lines (19 loc) · 615 Bytes
Breadcrumbs
algorithm
/
max_sum.py
Copy path
File metadata and controls
21 lines (19 loc) · 615 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
#coding:utf-8
def
max_array
(
lst
):
"""面试题:最大连续子数组,求一个有正,有负数的数组(有正和负数,没有全是负数的情况),
连续子数组之最大和。
迪艾姆python培训 黄哥所写 咨询:qq:1465376564
迪艾姆python远程视频培训班
要求时间复杂度为O(n)
"""
this_sum
=
0
max_sum
=
0
for
item
in
lst
:
this_sum
+=
item
if
this_sum
>
max_sum
:
max_sum
=
this_sum
elif
this_sum
<
0
:
this_sum
=
0
return
max_sum
test_lst
=
[
-
2
,
11
,
-
4
,
13
,
-
5
,
-
2
]
print
(
max_array
(
test_lst
))
Back
|
FazBrowse Home
|
New Git URL