码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode] Rotated Sorted Array

时间:2014-09-09 21:30:09      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   div   sp   log   on   

 1 public class Solution {
 2     public int search(int[] A, int target) {
 3         int low=0, high=A.length-1;
 4         
 5         while (low<high) {
 6             int mid=(low+high)/2;
 7             if (A[mid] < A[high]) {
 8                 if (target>A[mid] && target<=A[high]) low=mid+1;
 9                 else high=mid;
10             } else {
11                 if (target>=A[low] && target<=A[mid]) high=mid;
12                 else low=mid+1;
13             }
14         }
15         
16         if (A[low]==target) return low;
17         
18         return -1;
19     }
20 }

 

[LeetCode] Rotated Sorted Array

标签:style   blog   color   io   ar   div   sp   log   on   

原文地址:http://www.cnblogs.com/yuhaos/p/3963343.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!