From b5b0211d8a4ed25a4042bc1c3044111b71fb23e0 Mon Sep 17 00:00:00 2001 From: helloshalini <151553154+helloshalini@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:22:00 +0530 Subject: [PATCH] Add files via upload --- Maximum Subarray.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Maximum Subarray.cpp diff --git a/Maximum Subarray.cpp b/Maximum Subarray.cpp new file mode 100644 index 0000000..8790127 --- /dev/null +++ b/Maximum Subarray.cpp @@ -0,0 +1,47 @@ +// Problem Statement + +/* +Given an integer array nums, find the subarray with the largest sum, and return its sum. + +*/ + +// Solution + +#include +#include +using namespace std; +class Solution { +public: + int maxSubArray(vector& nums) { + int sum = 0; + int maxi = nums[0]; + + for(int i = 0 ; i