# 【题解】《算法零基础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

)">

)">
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://bcxiaobai.eu.org/post/310.html", "fetch_time": 1685807250000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2023-23/segments/1685224649293.44/warc/CC-MAIN-20230603133129-20230603163129-00321.warc.gz", "warc_record_offset": 159018362, "warc_record_length": 20282, "token_count": 544, "char_count": 1591, "score": 3.703125, "int_score": 4, "crawl": "CC-MAIN-2023-23", "snapshot_type": "latest", "language": "en", "language_score": 0.1964898407459259, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00008-of-00064.parquet"}