diff --git a/c++/Maximum Subarray.cpp b/c++/Maximum Subarray.cpp new file mode 100644 index 0000000..731d46a --- /dev/null +++ b/c++/Maximum Subarray.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +using namespace std; +int maxSubArray(vector nums) { + int n=nums.size(); + int max=0; + int curr=0; + for(int i=0;imax){ + max=curr; + } + if(curr<0){ + curr=0; + } + } + if(max>0){ + return max; + }else { + return *max_element(nums.begin(),nums.end()); + } +} +int main(){ + int a; + cout<<"Enter the size if the array : "; + cin>>a; + vector x; + for(int i=0;i>x[i]; + } + cout<