博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
leetCode 81.Search in Rotated Sorted Array II (旋转数组的搜索II) 解题思路和方法
阅读量:6713 次
发布时间:2019-06-25

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

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.

思路:此题在解的时候,才发现Search in Rotated Sorted Array的时候想复杂了,事实上仅仅须要遍历搜索就可以,线性时间。

代码例如以下:

public class Solution {    public boolean search(int[] nums, int target) {        for(int i = 0; i < nums.length; i++){            if(nums[i] == target){                return true;            }        }        return false;    }}

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

你可能感兴趣的文章
Python(四)装饰器、迭代器&生成器、re正则表达式、字符串格式化
查看>>
我的友情链接
查看>>
多个viewpager可能产生的问题
查看>>
理解自组织:敏捷里的自组织团队都是骗人的
查看>>
Java监控神器之psi-probe监控Tomcat和应用
查看>>
LCT
查看>>
VIJOS-P1635 城市连接
查看>>
chown命令详情
查看>>
强数学归纳法
查看>>
第三次作业结对编程
查看>>
jQuery总结(摘抄)
查看>>
_stat函数/struct stat 结构体使用笔记
查看>>
二分搜索 HDOJ 2289 Cup
查看>>
Byte[]、Image、Bitmap 之间的相互转换
查看>>
分布式全文检索引擎之ElasticSearch
查看>>
数组名和指针区别
查看>>
实现子数组和绝对值差最小 - Objective-C
查看>>
明天支付宝就开始提现收费了!这几招可以让你受用
查看>>
洛谷P4774 屠龙勇士
查看>>
第一次作业(个人作业)
查看>>