| 7 | class Solution { |
| 8 | public: |
| 9 | int maxSubArray(vector<int>& nums) { |
| 10 | |
| 11 | int cs=0; |
| 12 | int ms=INT_MIN; |
| 13 | // if size of array is 1 return that elemnt . |
| 14 | if(nums.size()==1){ |
| 15 | return nums[0]; |
| 16 | } |
| 17 | //Linearly traverse the array and add to the current sum variable and take maximum . |
| 18 | for (int i = 0; i < nums.size(); i++) { |
| 19 | cs=cs+nums[i]; |
| 20 | |
| 21 | |
| 22 | ms=max(cs,ms); |
| 23 | if(cs<0){ |
| 24 | cs=0; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | return ms; |
| 29 | } |
| 30 | |
| 31 | |
| 32 |
nothing calls this directly
no outgoing calls
no test coverage detected