最大子串乘積
輸入n個數,求它的最大的連續子串乘積。
例:輸入
1 2 -3 7 0 2 3
輸出**實現:
#include int max_subsegment(int * arr , int len)///-----最大子段乘積函式
else if( arr[j] > 0 )
else }}
return max;
}int main()///-----------main()
printf("%d\n",max_subsegment(&arr[0] , m));
printf("---------end--------\n\n");
}return 0;
}
案例:6
1 2 -3 -4 6 -7
168---------end--------
51 2 -3 4 6
24---------end--------
71 2 -3 7 0 2 3
7---------end--------
81 2 3 4 -5 6 7 4
168---------end--------
50 0 0 0 0
0---------end--------
process returned 0 (0x0) execution time : 128.646 s
press any key to continue.
乘積最大子串行
比如,序列 2,3,2,4 中乘積最大的子串行為 2,3 其乘積為6。方法一 自己一開始寫的方法比較麻煩。通過記錄陣列中元素為0的下標,然後以0為邊界,分割陣列,然後對每個分割後的陣列分別求最大乘積子串行,最後在所有的分割陣列的最大乘積子串行中取最大乘積。class solution int len...
最大子串行乘積
思路 以元素i結尾序列提供的最大正數記做 pos,最小負數記做 nag a n 大於零時 pos n max max value max 若n 1位置存在最小負數,更新 nag n nag n 1 a n a n 小於零時 pos n max max value max 更新 nag n min a...
乘積最大子串行
給定乙個整數陣列 nums 找出乙個序列中乘積最大的連續子串行 該序列至少包含乙個數 示例 1 輸入 2,3,2,4 輸出 6 解釋 子陣列 2,3 有最大乘積 6。示例 2 輸入 2,0,1 輸出 0 解釋 結果不能為 2,因為 2,1 不是子陣列。由於存在負數,那麼最大的數可能變最小的數,最小的...