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

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

https://leetcode.com/problems/search-in-rotated-sorted-array-ii/description/ Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-time complexity? How and why? Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). Write a function to determine if a given target is in the array. make sure also checks the
1 public boolean search(int[] nums, int target) { 2         if (nums == null || nums.length ==0 ) return false ; 3         int left = 0, right = nums.length - 1 ; 4         while (left + 1 < right){ 5             int mid = left + (right - left) /2 ; 6             if (nums[mid] == target) return true; 7             /*when left == mid or mid == right this will not provide any useful info(could not determine the range) 8              */ 9             if (nums[left] == nums[mid] ){10                 left ++ ;11             }12             if (nums[mid] == nums[right]){13                 right--;14             }15             //upper part16             if (nums[left]

 

转载于:https://www.cnblogs.com/davidnyc/p/8587051.html

你可能感兴趣的文章
# 编写第一个Chrome Extension
查看>>
Python--Redis实战:第五章:使用Redis构建支持程序:第1节:使用Redis来记录日志...
查看>>
2019 简易Web开发指南
查看>>
H5拍照、选择图片上传组件核心
查看>>
单词纠错
查看>>
你可能不知道的14个JavaScript调试技巧
查看>>
nodejs遍历文件夹下并操作HTML/CSS/JS/PNG/JPG
查看>>
根据背景颜色的亮度调整字体的颜色
查看>>
python requests socks代理
查看>>
PHP socket初探 --- 含着泪也要磕完libevent(三)
查看>>
白鹭引擎王泽:重度H5游戏性能优化技巧
查看>>
PHP编译参数configure配置详解(持续更新中)
查看>>
ios 服务器端php推送证书生成
查看>>
多列布局(column)
查看>>
用Python写算法 | 蓄水池算法实现随机抽样
查看>>
canvas核心技术-如何绘制线段
查看>>
数组去重方法总结
查看>>
React 事件系统
查看>>
Android Architecture Components Part4:ViewModel
查看>>
weex开发问题记录
查看>>