博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
搜索旋转排序数组 II
阅读量:4166 次
发布时间:2019-05-26

本文共 437 字,大约阅读时间需要 1 分钟。

一、题目:

假设按照升序排序的数组在预先未知的某个点上进行了旋转。

( 例如,数组 [0,0,1,2,2,5,6] 可能变为 [2,5,6,0,0,1,2] )。

编写一个函数来判断给定的目标值是否存在于数组中。若存在返回 true,否则返回 false。

示例 1:

输入: nums = [2,5,6,0,0,1,2], target = 0

输出: true
示例 2:

输入: nums = [2,5,6,0,0,1,2], target = 3

输出: false
进阶:

这是 搜索旋转排序数组 的延伸题目,本题中的 nums 可能包含重复元素。

二、思路:

遍历一遍数组,遇到相同的数就返回1;

三、代码和结果:

class Solution {
public:int flag = 2; bool search(vector
& nums, int target) {
for(int i=0;i

结果:

在这里插入图片描述

转载地址:http://anexi.baihongyu.com/

你可能感兴趣的文章
mongodb数据导入导出以及备份恢复(二)
查看>>
mongodb数据导入导出以及备份恢复(三)
查看>>
mongodb数据导入导出以及备份恢复
查看>>
python整理二十七——egg文件制作与安装【仅提供链接地址】
查看>>
十一新疆之旅中邂逅的一首诗《黄河,母亲之河》
查看>>
【MongoDB】The description of index(一)
查看>>
MongoDB索引学习笔记
查看>>
【MonogDB】The description of index(二) Embedded and document Index
查看>>
【MonogDB】The description of index(三) Compose and unique Index
查看>>
【MongoDB】The basic operation of Index in MongoDB
查看>>
【MongoDB】The connection between two tables
查看>>
【MongoDB】windows下搭建Mongo主(Master)/从(slave)数据库同步
查看>>
【MongoDB】以前学习mongodb知识的补充
查看>>
【MongoDB】The description of procedure in MongoDB
查看>>
【MongoDB】mongoimport and mongoexport of data (一)
查看>>
【MongoDB】mongoimport and mongoexport of data (二)
查看>>
【MongoDB】mongodump and mongorestore of mogodb
查看>>
【MongoDB】The Access control of mongodb
查看>>
【MongoDB】windows平台搭建Mongo数据库复制集(类似集群)(一)
查看>>
【MongoDB】深入了解MongoDB不可不知的十点
查看>>