zoukankan      html  css  js  c++  java
  • Find Minimum in Rotated Sorted Array II 旋转数组中找最小值(有反复元素) @LeetCode

    递归


    public class Solution {
        public int findMin(int[] num) {
            return helper(num, 0, num.length-1);
        }
        
        //with duplicate
        public static int helper(int[] a, int left, int right){
             
            //one element
            if(left == right){
                return a[left];
            }
             
            //two elements
            if(left == right-1){
                return a[left]<a[right]? a[left]: a[right];
            }
             
            //the array is ordered
            if(a[left] < a[right]){
                return a[left];
            }
             
            int mid = (left+right)/2;
             
            if(a[mid] > a[left]){
                return helper(a, mid, right);
            }else if(a[mid] < a[left]){
                return helper(a, left, mid);
            }else{ //when a[mid] == a[left], we have to search both side
                return Math.min(helper(a, mid, right), helper(a, left, mid));
            }
             
        }
    }





  • 相关阅读:
    Dynamic导出解决方案修改其XML信息
    子网格
    官方文档
    ADFS登录页面自定义
    ADFS设置Tokn生命周期
    特征工程
    Pandas
    分类决策树
    Python基本知识
    机器学习的基本概念
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/6991533.html
Copyright © 2011-2022 走看看