{
  "type": "code_options",
  "author": "https://github.com/begeekmyfriend/leetcode",
  "source": "solution.md",
  "exercise_id": "1227f881a77741199e38d9fa69318778",
  "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": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <bits/stdc++.h>\nusing namespace std;\nclass Solution\n{\npublic:\n\tint maxSubArray(vector<int> &nums)\n\t{\n\t\tint sum = 0, max_sum = INT_MIN;\n\t\tfor (int i = 0; i < nums.size(); i++)\n\t\t{\n\t\t\tif (sum < 0)\n\t\t\t{\n\t\t\t\tsum = nums[i];\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tsum += nums[i];\n\t\t\t}\n\t\t\tmax_sum = max(sum, max_sum);\n\t\t}\n\t\treturn max_sum;\n\t}\n};",
    "language": "cpp"
  },
  "node_id": "dailycode-ec47904e86d843648adbe57362e3fb25",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600469821"
}