几个数公有的因数叫做这几个数的公因数,公因数中最大的叫做这几个数的最大公因数。例如6和15的最大公因数为3,4和8的最大公因数为4。 现在给出一个长度为n的数组[n1,n2…nn],求计算出他们的最大公因数。
示例1
输入
[2,3]
输出
1
示例2
输入
[2,4]
输出
2
示例3
输入
[1,2,3,4]
输出
1
示例4
输入
[88,77,66]
输出
11
示例5
输入
[]
输出
-1
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * 斐波那契数列 * @param L int整型一维数组 整形数组 * @return int整型 */ public int cal_max_common_factor (int[] L) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * 斐波那契数列 * @param L int整型一维数组 整形数组 * @param LLen int L数组长度 * @return int整型 */ int cal_max_common_factor(int* L, int LLen) { // write code here } };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # 斐波那契数列 # @param L int整型一维数组 整形数组 # @return int整型 # class Solution: def cal_max_common_factor(self , L ): # write code here
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * 斐波那契数列 * @param L int整型一维数组 整形数组 * @return int整型 */ function cal_max_common_factor( L ) { // write code here } module.exports = { cal_max_common_factor : cal_max_common_factor };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # 斐波那契数列 # @param L int整型一维数组 整形数组 # @return int整型 # class Solution: def cal_max_common_factor(self , L ): # write code here
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * 斐波那契数列 * @param L int整型一维数组 整形数组 * @return int整型 */ func cal_max_common_factor( L []int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * 斐波那契数列 * @param L int整型一维数组 整形数组 * @param LLen int L数组长度 * @return int整型 */ int cal_max_common_factor(int* L, int LLen ) { // write code here }
[2,3]
1
[2,4]
2
[1,2,3,4]
1
[88,77,66]
11
[]
-1