Created
July 23, 2013 06:34
-
-
Save riyadparvez/6060269 to your computer and use it in GitHub Desktop.
Returns largest subsequence sum in C#.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static double LargestSubsequenceSum(IEnumerable<double> list) | |
| { | |
| var arr = list.ToArray(); | |
| double currentMax = arr[0]; | |
| double max = currentMax; | |
| for (int i = 1; i < arr.Length; i++) | |
| { | |
| currentMax = Max(currentMax, currentMax+arr[i]); | |
| max = Max(max, currentMax); | |
| } | |
| return max; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment