-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modified code Largest Sum Contiguous Subarray [C, Java] #421
Conversation
@@ -14,12 +14,9 @@ public static int largestSumContiguousSubarray(int[] array) { // maximum sum | |||
prevSum = array[0]; // initialize current sum amd previous sum | |||
currentSum = array[0]; | |||
for (i = 1; i < array.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i
can be declared here only like for (int i = 1; i < array.length; i++)
and remove line 13
} | ||
|
||
int main() { | ||
int array[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4, 5}; | ||
printf("%d", largestSumContinousSubArray(array, 10)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either change Continous
to Continuous
(as previous one is type) or Contiguous
(as filename suggests).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of 10
place size
there; where size = sizeof(array)/sizeof(array[0]);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See Comments
} | ||
|
||
int main() { | ||
int array[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4, 5}; | ||
printf("%d", largestSumContinousSubArray(array, 10)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of 10
place size
there; where size = sizeof(array)/sizeof(array[0]);
} | ||
|
||
int main() { | ||
int array[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4, 5}; | ||
printf("%d", largestSumContinousSubArray(array, 10)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of %d
use %d\n
|
||
int main() { | ||
int array[] = {-2, 1, -3, 4, -1, 2, 1, -5, 4, 5}; | ||
int size = sizeof(array)/sizeof(array[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add whitespace around /
and its done. 👍
@@ -1,25 +1,27 @@ | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
|
|||
int largestSumContinousSubArray(int arr[], int size) { | |||
int largestSumContiguousSubArray(int arr[], int size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be largestSumContiguousSubarray
. i.e. same as filename.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsroyal We should rename the file to ...SubArray.c
int array[10]; | ||
for (int k = 0; k < 10; k++) { | ||
array[k] = rand() % 10; | ||
int max(int first, int second) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#define max(a,b) (((a)>(b)) ? (a) : (b))
Better use this.
|
||
int largestSumContinousSubArray(int arr[], int size) { | ||
int largestSumContiguousSubarray(int arr[], int size) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsroyal Sir please fix the function name as per C guidelines.
@jsroyal: Please reopen if you wish to continue. |
Fixes #420
By submitting this pull request I confirm I've read and complied with the below declarations.
Added {Algorithm/DS name} [{Language}]
, notUpdate README.md
orAdded new code
.