
NumberGameIII
You’re given an array S
of positive integers.
Return number x
from S
, such that each number of S
is a multiple of x
, or -1
if such x
doesn’t exist.
Examples:
-
For
s=[3,6,3,15,9]
the output should beNumberGameIII(s)=3.
Each number ofS
is a multiple of3
, and3
belongs toS
, so the answer is3
. -
For s=[4,7] the output should be NumberGameIII(s)=-1.
7
is not a multiple of4
.4
is not a multiple of7
. So the answer is-1
.
Input/Output:
-
[execution time limit] 0.5 seconds
-
[input] array.integer S
An array of positive integers.
-
[output] integer
x
if suchx
exists,-1
otherwise.
Post Comment