{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "a53ecd2c41fa4c10ae30759ef1229b6f",
  "keywords": "数组,分治,动态规划",
  "title": "最大子序和",
  "desc": [
    {
      "content": "\n<p>给定一个整数数组 <code>nums</code> ，找到一个具有最大和的连续子数组（子数组最少包含一个元素），返回其最大和。</p><p> </p><p><strong>示例 1：</strong></p><pre><strong>输入：</strong>nums = [-2,1,-3,4,-1,2,1,-5,4]<strong><br />输出：</strong>6<strong><br />解释：</strong>连续子数组 [4,-1,2,1] 的和最大，为 6 。</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>nums = [1]<strong><br />输出：</strong>1</pre><p><strong>示例 3：</strong></p><pre><strong>输入：</strong>nums = [0]<strong><br />输出：</strong>0</pre><p><strong>示例 4：</strong></p><pre><strong>输入：</strong>nums = [-1]<strong><br />输出：</strong>-1</pre><p><strong>示例 5：</strong></p><pre><strong>输入：</strong>nums = [-100000]<strong><br />输出：</strong>-100000</pre><p> </p><p><strong>提示：</strong></p><ul>\t<li><code>1 <= nums.length <= 3 * 10<sup>4</sup></code></li>\t<li><code>-10<sup>5</sup> <= nums[i] <= 10<sup>5</sup></code></li></ul><p> </p><p><strong>进阶：</strong>如果你已经实现复杂度为 <code>O(n)</code> 的解法，尝试使用更为精妙的 <strong>分治法</strong> 求解。</p>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "class Solution {\n\tpublic int maxSubArray(int[] nums) {\n\t\tint maxSum = nums[0];\n\t\tint curSum = 0;\n\n\t\tfor (int n : nums) {\n\t\t\tcurSum += n;\n\t\t\tif (curSum > maxSum) {\n\t\t\t\tmaxSum = curSum;\n\t\t\t}\n\t\t\tif (curSum < 0) {\n\t\t\t\tcurSum = 0;\n\t\t\t}\n\t\t}\n\n\t\treturn maxSum;\n\t}\n}\n",
    "language": "java"
  },
  "node_id": "dailycode-3cd29560f5674e679333d243e81115c0",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600469821"
}