Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
competitive
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bruno Freitas Tissei
competitive
Commits
c2250cd9
Commit
c2250cd9
authored
7 years ago
by
Bruno Freitas Tissei
Browse files
Options
Downloads
Patches
Plain Diff
Add kadane
Signed-off-by:
Bruno Freitas Tissei
<
bft15@inf.ufpr.br
>
parent
d1279cbe
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
paradigm/kadane.cpp
+31
-0
31 additions, 0 deletions
paradigm/kadane.cpp
with
31 additions
and
0 deletions
paradigm/kadane.cpp
0 → 100644
+
31
−
0
View file @
c2250cd9
/**
* Kadane
*
* Complexity (Time): O(n + m)
* Complexity (Space): O(n + m)
*/
int
v
[
MAX
];
int
kadane
()
{
// Maximum so far (msf), Maximum ending here (meh).
int
msf
=
-
0x3f3f3f3f
,
meh
=
0
;
int
start
=
0
,
end
=
0
,
s
=
0
;
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
meh
+=
v
[
i
];
if
(
msf
<
meh
)
{
msf
=
meh
;
start
=
s
;
end
=
i
;
}
if
(
meh
<
0
)
{
meh
=
0
;
s
=
i
+
1
;
}
}
return
msf
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment