[leetcode]154 Find Minimum in rotated Sorted Array II

Source: Internet
Author: User

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

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

Public class solution {    public int findmin (Int[] num)  {                //  solution a:        // return findmin_iteration ( NUM);                //  Solution b:        return findmin_recursion (Num, 0, &NBSP;NUM.LENGTH&NBSP;-&NBSP;1);    }             ////////////////    // Solution A: Iteration     //    private int findmin_iteration (int[] num)      {        int lo = 0;         int hi = num.length- 1;        int mid =  0;        while (Lo < hi)  {             mid = lo +  (Hi - lo)  /  2;            if  (num[mid] >  num[hi])  {                 lo = mid + 1;             }            else if  (num[ Mid] < num[hi])  {                 hi = mid;             }             else { // when num[mid] and num[hi]  are same                 hi--;            }         }        return num[lo];     }    ////////////////    // Solution B:  Recursion    //    private int findmin_recursion (int[]  N, int low, int high)     {         if  (Low == high)              return n[low];                 if  (LOW&NBSP;+&NBsp;1 == high)             return  Math.min (N[low], n[high]);                     int mid = low +  (High - low)  / 2;                 if  (N[low] < n[mid] && n[low] < n[high])          {             Return findmin_recursion (N, low, mid);        }         else if  (n[low] > n[mid] &&  n[low] > n[high])         {              return findmin_recursion (N, low, mid);         }        else // i don ' t know         {             Return findmin_recursion (N, low + 1, high);         }    }}


[leetcode]154 Find Minimum 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.