[leetcode]81 Search in rotated Sorted Array II

Source: Internet
Author: User

https://oj.leetcode.com/problems/search-in-rotated-sorted-array-ii/

http://blog.csdn.net/linhuanmars/article/details/20588511

Public class solution {    public boolean search (Int[] A,  int target)  {        if  (a == null  | |  a.length == 0)             return  false;        return find (A, 0, A.length -  1, target);     }        // o (n)     private boolean find (Int[] a, int low, int high,  int t)     {        if  (low  > high)             return false;                      if  (low  == high)             return A[low]  == t;                     int mid =  (Low + high)  / 2;                 if  (a[mid] == t)              return true;                     if  (A[mid ] > a[low])         {             if  (a[low] <= t && t < a[ MID])                 return  find (A, low,  mid - 1, t); // left part             else                 return find (a, mid + 1, high, t);         }        else if  (a[mid] <  a[low])         {             if  (T > a[mid] && t <= a[high])                  return find (A, &NBSP;MID&NBSP;+&NBSP;1,&NBSP;HIGH,&NBSP;T); // right part             else                &nbSp;return find (a, low, mid - 1, t);         }        else        {             return find (A, low + &NBSP;1,&NBSP;HIGH,&NBSP;T); // just shift left.         }    }}


[leetcode]81 Search in rotated Sorted Array II

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.