FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/split-array-with-equal-sum.py at master · pythonpeixun/LeetCode-Solutions · GitHub
pythonpeixun
/
LeetCode-Solutions
Public
forked from
kamyu104/LeetCode-Solutions
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
split-array-with-equal-sum.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
27 lines (24 loc) · 926 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
split-array-with-equal-sum.py
Copy path
File metadata and controls
27 lines (24 loc) · 926 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
24
25
26
# Time: O(n^2)
# Space: O(n)
class
Solution
(
object
):
def
splitArray
(
self
,
nums
):
"""
:type nums: List[int]
:rtype: bool
"""
if
len
(
nums
)
<
7
:
return
False
accumulated_sum
=
[
0
]
*
len
(
nums
)
accumulated_sum
[
0
]
=
nums
[
0
]
for
i
in
xrange
(
1
,
len
(
nums
)):
accumulated_sum
[
i
]
=
accumulated_sum
[
i
-
1
]
+
nums
[
i
]
for
j
in
xrange
(
3
,
len
(
nums
)
-
3
):
lookup
=
set
()
for
i
in
xrange
(
1
,
j
-
1
):
if
accumulated_sum
[
i
-
1
]
==
accumulated_sum
[
j
-
1
]
-
accumulated_sum
[
i
]:
lookup
.
add
(
accumulated_sum
[
i
-
1
])
for
k
in
xrange
(
j
+
2
,
len
(
nums
)
-
1
):
if
accumulated_sum
[
-
1
]
-
accumulated_sum
[
k
]
==
accumulated_sum
[
k
-
1
]
-
accumulated_sum
[
j
]
and
\
accumulated_sum
[
k
-
1
]
-
accumulated_sum
[
j
]
in
lookup
:
return
True
return
False
Back
|
FazBrowse Home
|
New Git URL