FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
AlgorithmVisualizer/algorithm/dp/max_subarray/basic/code.js at master · qcobber/AlgorithmVisualizer · GitHub
qcobber
/
AlgorithmVisualizer
Public
forked from
algorithm-visualizer/algorithm-visualizer
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
AlgorithmVisualizer
/
algorithm
/
dp
/
max_subarray
/
basic
/
code.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (23 loc) · 878 Bytes
Breadcrumbs
AlgorithmVisualizer
/
algorithm
/
dp
/
max_subarray
/
basic
/
code.js
Copy path
File metadata and controls
30 lines (23 loc) · 878 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
27
28
29
30
var
maxSubarraySum
=
(
function
maxSubarray
(
array
)
{
var
maxSoFar
=
0
,
maxEndingHere
=
0
;
logger
.
_print
(
'Initializing maxSoFar = 0 & maxEndingHere = 0'
)
;
for
(
var
i
=
0
;
i
<
array
.
length
;
i
++
)
{
tracer
.
_select
(
i
)
;
logger
.
_print
(
maxEndingHere
+
' + '
+
array
[
i
]
)
;
maxEndingHere
+=
array
[
i
]
;
logger
.
_print
(
'=> '
+
maxEndingHere
)
;
if
(
maxEndingHere
<
0
)
{
logger
.
_print
(
'maxEndingHere is negative, set to 0'
)
;
maxEndingHere
=
0
;
}
if
(
maxSoFar
<
maxEndingHere
)
{
logger
.
_print
(
'maxSoFar < maxEndingHere, setting maxSoFar to maxEndingHere ('
+
maxEndingHere
+
')'
)
;
maxSoFar
=
maxEndingHere
;
}
tracer
.
_wait
(
)
;
tracer
.
_deselect
(
i
)
;
}
return
maxSoFar
;
}
)
(
D
)
;
logger
.
_print
(
'Maximum Subarray\'s Sum is: '
+
maxSubarraySum
)
;
Back
|
FazBrowse Home
|
New Git URL