{
  "type": "code_options",
  "author": "https://github.com/qiyuangong/leetcode",
  "source": "solution.md",
  "exercise_id": "63f84e83edcc43819d0650cd2fc897d9",
  "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": "python"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ],
    [
      {
        "content": "",
        "language": "python"
      }
    ]
  ],
  "template": {
    "content": "class Solution:\n\tdef searchInsert(self, nums, target):\n\t\tl, r = int(0), len(nums) - 1\n\t\twhile l < r:\n\t\t\tmid = int((l + r) / 2)\n\t\t\tif nums[mid] < target:\n\t\t\t\tl = mid + 1\n\t\t\telse:\n\t\t\t\tr = mid\n\t\tif nums[l] < target:\n\t\t\treturn l + 1\n\t\treturn l \nif __name__ == '__main__':\n\ts = Solution()\n\tprint (s.searchInsert([1,3,5,6],5))\t",
    "language": "python"
  },
  "node_id": "dailycode-9290d8e155064971b7dac798bc6e3b30",
  "license": "csdn.net",
  "created_at": 1637894161,
  "topic_link": "https://bbs.csdn.net/topics/600470222"
}