less than 1 minute read

Given a list of positive integers nums, return the largest positive integer that divides each of the integers.

Constraints

  • 1 ≤ n ≤ 100,000 where n is the length of nums

https://binarysearch.com/problems/Greatest-Common-Divisor

Examples

Example 1

Input

  • nums = [6, 12, 9]

Output

  • answer = 3

Explanation

3 is the largest integer that divides into 6, 12, and 9.

Example 2

Input

  • nums = [6, 7, 9]

Output

  • answer = 1

Explanation

7 is a prime number so only 1 divides into it.

Solution

Leave a comment