Leetcode no. 81
2016-04-13 21:50
211 查看
81. Search in Rotated Sorted Array II
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.
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.
public class Solution { public boolean search(int[] nums, int target) { if (nums.length==0) return false; int start= 0, end= nums.length-1; while (start < end){ int center= (start+end)/2; if (nums[center] == target) return true; if (nums[center]> nums[end]){ if (target < nums[center] && target>= nums[start]) end= center; else start= center+1; }else if (nums[center]< nums[end]){ if (target > nums[center] && target<=nums[end]) start= center+1; else end= center; } else end--; } return nums[end]== target? true : false; } }
相关文章推荐
- 数据结构实验之求二叉树后序遍历和层次遍历
- hdu 5182 PM2.5
- nrf51822开发指导之静态密钥配对--在SDK9.0的ble_app_uart例程修改
- 练习26 复杂链表拷贝
- ubuntu软件源-sources.list
- 数据库去重
- C++混合编程之idlcpp教程Python篇(6)
- 第六周-单元测试
- 第六周作业 -内聚耦合
- Accelerated tensor_toolbox version 1.0
- Jsp自定义标签
- Android版股票K线图实现方案
- git常用命令行
- Java和Flex整合报错(四)
- mfc配置GDI+有106个错误
- bailian--oj--2757(最长上升子序列)
- [POJ 2566] Bound Found (TwoPointer入门)
- Vim的使用
- java代码生成二维码
- LINUX内核分析第八周学习总结:进程的切换和系统的一般执行过程