{
  "type": "code_options",
  "author": "https://github.com/begeekmyfriend/leetcode",
  "source": "solution.md",
  "exercise_id": "2a48f3f173ad4d5eb687f2b17a53d8ac",
  "keywords": "数组,二分查找",
  "title": "搜索插入位置",
  "desc": [
    {
      "content": "\n<p>给定一个排序数组和一个目标值，在数组中找到目标值，并返回其索引。如果目标值不存在于数组中，返回它将会被按顺序插入的位置。</p><p>你可以假设数组中无重复元素。</p><p><strong>示例 1:</strong></p><pre><strong>输入:</strong> [1,3,5,6], 5<strong><br />输出:</strong> 2</pre><p><strong>示例&nbsp;2:</strong></p><pre><strong>输入:</strong> [1,3,5,6], 2<strong><br />输出:</strong> 1</pre><p><strong>示例 3:</strong></p><pre><strong>输入:</strong> [1,3,5,6], 7<strong><br />输出:</strong> 4</pre><p><strong>示例 4:</strong></p><pre><strong>输入:</strong> [1,3,5,6], 0<strong><br />输出:</strong> 0</pre>",
      "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 searchInsert(vector<int> &nums, int target)\n\t{\n\t\tint lo = -1;\n\t\tint hi = nums.size();\n\t\twhile (lo + 1 < hi)\n\t\t{\n\t\t\tint mid = lo + (hi - lo) / 2;\n\t\t\tif (target > nums[mid])\n\t\t\t{\n\t\t\t\tlo = mid;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\thi = mid;\n\t\t\t}\n\t\t}\n\t\treturn hi;\n\t}\n};",
    "language": "cpp"
  },
  "node_id": "dailycode-c0d349cc79bc43b6b66a4e561c11adb4",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600470222"
}