# 【题解】《算法零基础100讲》(第17讲) 线性枚举(一) – 最值算法（java版）

?算法小白欢迎加入此社区：https://bbs.csdn.net/forums/hero?category=0

?

``````class Solution {
public int findMaxConsecutiveOnes(int[] nums) {
int number = 0;
int count = 0;
for(int i = 0; i < nums.length; i++){
if(nums[i] == 1){
count++;
number = Math.max(number, count);
}else{
count = 0;
}
}
return number;
}
}

``````

``````class Solution {
public int maxProduct(int[] nums) {
Arrays.sort(nums);
int i,max;
for(i=0; i<nums.length; i++){
nums[i] = nums[i] - 1;
}
int len = nums.length;
max = nums[len-1] * nums[len-2];
return max;
}
}
``````

``````class Solution {
public int findMin(int[] nums) {
Arrays.sort(nums);
return nums[0];
}
}
``````

``````class Solution {
public int findMin(int[] nums) {
int low = 0, high = nums.length-1;
while(low < high){
int mid = low + (high - low)/2;
if(nums[mid] <= nums[high]){
high = mid;
}else{
low = mid+1;
}
}
return nums[low];
}
}
``````

``````class Solution {
public int findMin(int[] nums) {
Arrays.sort(nums);
return nums[0];
}
}
``````

``````class Solution {
public int thirdMax(int[] nums) {
Set set= new HashSet();//发生多态(Set集合具有互异性)
for (int i:nums) {
}
Object[] array=set.toArray();
Arrays.sort(array);
int len=array.length;
if(len>=3){
return (int) array[len-3];
}
return (int) array[len-1];
}
}
``````

``````class Solution {
public int maximumProduct(int[] nums) {
Arrays.sort(nums);
int max = nums[nums.length-1]*nums[nums.length-2]*nums[nums.length-3];
int maxn = nums[0]*nums[1]*nums[nums.length-1];
if(max > maxn){
return max;
}else{
return maxn;
}
}
}
``````

（今日立冬，今日大雪）

THE END

)">

)">