{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "e082f85c05944fadb19a3fa01a518afb",
  "keywords": "数组,二分查找",
  "title": "搜索旋转排序数组 II",
  "desc": [
    {
      "content": "\n<p>已知存在一个按非降序排列的整数数组 <code>nums</code> ，数组中的值不必互不相同。</p>\n<p>在传递给函数之前，<code>nums</code> 在预先未知的某个下标 <code>k</code>（<code>0 <= k < nums.length</code>）上进行了 <strong>旋转\n</strong>，使数组变为 <code>[nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]]</code>（下标 <strong>从 0\n开始</strong> 计数）。例如， <code>[0,1,2,4,4,4,5,6,6,7]</code> 在下标 <code>5</code> 处经旋转后可能变为\n<code>[4,5,6,6,7,0,1,2,4,4]</code> 。\n</p>\n<p>给你 <strong>旋转后</strong> 的数组 <code>nums</code> 和一个整数 <code>target</code> ，请你编写一个函数来判断给定的目标值是否存在于数组中。如果\n<code>nums</code> 中存在这个目标值 <code>target</code> ，则返回 <code>true</code> ，否则返回 <code>false</code> 。\n</p>\n<p> </p>\n<p><strong>示例 1：</strong></p>\n<pre><strong>输入：</strong>nums = [2,5,6,0,0,1,2], target = 0<strong><br />输出：</strong>true</pre>\n<p><strong>示例 2：</strong></p>\n<pre><strong>输入：</strong>nums = [2,5,6,0,0,1,2], target = 3<strong><br />输出：</strong>false</pre>\n<p> </p>\n<p><strong>提示：</strong></p>\n<ul>\n<li><code>1 <= nums.length <= 5000</code></li>\n<li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li>\n<li>题目数据保证 <code>nums</code> 在预先未知的某个下标上进行了旋转</li>\n<li><code>-10<sup>4</sup> <= target <= 10<sup>4</sup></code></li>\n</ul>\n<p> </p>\n<p><strong>进阶：</strong></p>\n<ul>\n<li>这是 <a\nhref=\"https://leetcode-cn.com/problems/search-in-rotated-sorted-array/description/\">搜索旋转排序数组</a> 的延伸题目，本题中的 <code>nums</code> \n可能包含重复元素。</li>\n<li>这会影响到程序的时间复杂度吗？会有怎样的影响，为什么？</li>\n</ul>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "class Solution {\n\tpublic boolean search(int[] nums, int target) {\n\t\tint low = 0;\n\t\tint high = nums.length - 1;\n\t\twhile (low <= high) {\n\t\t\twhile (low < high && nums[low] == nums[low + 1]) {\n\t\t\t\tlow++;\n\t\t\t}\n\t\t\twhile (low < high && nums[high] == nums[high - 1]) {\n\t\t\t\thigh--;\n\t\t\t}\n\t\t\tint mid = (low + high) / 2;\n\t\t\tif (nums[mid] == target) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tif (nums[mid] >= nums[0] && (target > nums[mid] || target < nums[0])) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else if (nums[mid] < nums[0] && target > nums[mid] && target < nums[0]) {\n\t\t\t\tlow = mid + 1;\n\t\t\t} else {\n\t\t\t\thigh = mid - 1;\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n}",
    "language": "java"
  },
  "node_id": "dailycode-97b59f64908e447ca8f6cc62c7d69b2a",
  "license": "csdn.net",
  "created_at": 1637894159,
  "topic_link": "https://bbs.csdn.net/topics/600469924"
}