博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LeetCode - Search in Rotated Sorted Array II
阅读量:6974 次
发布时间:2019-06-27

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

题目:

Follow up for "Search in Rotated Sorted Array":

What if duplicates are allowed?
Would this affect the run-time complexity? How and why?
Write a function to determine if a given target is in the array.

 

思路:

直接循环一遍查找

package array;public class SearchInRotatedSortedArrayII {    public boolean search(int[] nums, int target) {        int len;        if (nums == null || (len = nums.length) == 0) return false;        for (int i = 0; i < len; ++i)             if (nums[i]==target)                return true;        return false;    }        public static void main(String[] args) {        // TODO Auto-generated method stub        int[] nums = { 3, 1, 1 };        SearchInRotatedSortedArrayII s = new SearchInRotatedSortedArrayII();        System.out.println(s.search(nums, 3));    }}

 

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

你可能感兴趣的文章
C#写爬虫,版本V2.0
查看>>
基于Ubuntu16搭建Hadoop大数据完全分布式环境
查看>>
网络爬虫
查看>>
python-memcached学习笔记
查看>>
转--Java工程师成神之路(2018修订版)
查看>>
学习python第一天内容回顾
查看>>
原码,补码表示
查看>>
(最长上升子序列 并记录过程)FatMouse's Speed -- hdu -- 1160
查看>>
面面观 | CentOS install etcd 测试
查看>>
[CF566A]Matching Names
查看>>
[Oracle]ORA-01461: can bind a LONG value only for insert into a LONG column
查看>>
Linux学习之CentOS(三十三)--DNS基础及域名系统架构
查看>>
算法整理
查看>>
作业(二)
查看>>
计数排序
查看>>
nginx 和 php超时设置
查看>>
[复变函数]第03堂课 1.2 复平面上的点集
查看>>
Servlet学习之web服务器Tomcat 详解
查看>>
Python:Opening Python Classes
查看>>
mvc:view-controller
查看>>