---
# System prepended metadata

title: 53. Maximum Subarray
tags: [DP]

---

---
title: 53. Maximum Subarray
tags: DP
description: share source code.
---

# 53. Maximum Subarray

```java=
class Solution {
    public int maxSubArray(int[] nums) {
        int n = nums.length;
        int sum = 0;
        int max = -100001;
        for(int i = 0; i < n; i++){
            sum = Math.max(sum + nums[i], nums[i]);
            max = Math.max(max, sum);
        }
        return max;
    }
}
```

