81. Search in Rotated Sorted Array II
2016-03-21 11:10
363 查看
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.
Subscribe to see which companies asked this question
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.
Subscribe to see which companies asked this question
public class Solution { public boolean search(int[] nums, int target) { int a = 0,c = nums.length-1; while(a<=c){ int b = (a+c)>>1; if(nums[b]==target)return true; if(nums[a]==nums[b]&&nums[a]==nums[c]){ a++; c--; }else if(nums[a]<=nums[b]){ if(nums[a]<=target&&target<nums[b]){ c=b-1; }else{ a=b+1; } }else{ if(nums[b]<target&&target<=nums[c]){ a=b+1; }else{ c=b-1; } } } return false; } }
相关文章推荐
- Level Order Traversal 图的层序遍历 cpp
- 将子控件插入指定位置
- String、StringBuffer与StringBuilder之间区别
- 记录心路历程
- 279. Perfect Squares
- 解决android 单击事件和移动事件的冲突
- 35 个 Java 代码性能优化总结
- 我的工作脚本
- MATLAB 编程风格指南
- 朴素贝叶斯
- 机器学习中方差与偏差的理解
- 全面阐述overflow:hidden属性 (清除立体浮动)
- php变量覆盖漏洞
- 分享 13 个帮助你简化开发的 jQuery 插件
- 心中有佛,看谁都是佛;心中有屎,看谁都是屎。
- 用jquery控制图片的最大宽度
- 如何让百度收录以图文显示
- 给你一个故事,希望你能喜欢这个故事并希望它能为你带来好运。
- php环境 wamp apache 怎么支持asp? 2003的系统
- 让wamp apache 支持asp的 ActiveHTML组件