Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b47b95d

Browse files
committed
Add solution #1979
1 parent 4e3d96c commit b47b95d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,666 LeetCode solutions in JavaScript
1+
# 1,667 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1518,6 +1518,7 @@
15181518
1975|[Maximum Matrix Sum](./solutions/1975-maximum-matrix-sum.js)|Medium|
15191519
1976|[Number of Ways to Arrive at Destination](./solutions/1976-number-of-ways-to-arrive-at-destination.js)|Medium|
15201520
1977|[Number of Ways to Separate Numbers](./solutions/1977-number-of-ways-to-separate-numbers.js)|Hard|
1521+
1979|[Find Greatest Common Divisor of Array](./solutions/1979-find-greatest-common-divisor-of-array.js)|Easy|
15211522
1980|[Find Unique Binary String](./solutions/1980-find-unique-binary-string.js)|Medium|
15221523
1985|[Find the Kth Largest Integer in the Array](./solutions/1985-find-the-kth-largest-integer-in-the-array.js)|Medium|
15231524
1996|[The Number of Weak Characters in the Game](./solutions/1996-the-number-of-weak-characters-in-the-game.js)|Medium|
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 1979. Find Greatest Common Divisor of Array
3+
* https://leetcode.com/problems/find-greatest-common-divisor-of-array/
4+
* Difficulty: Easy
5+
*
6+
* Given an integer array nums, return the greatest common divisor of the smallest number and
7+
* largest number in nums.
8+
*
9+
* The greatest common divisor of two numbers is the largest positive integer that evenly
10+
* divides both numbers.
11+
*/
12+
13+
/**
14+
* @param {number[]} nums
15+
* @return {number}
16+
*/
17+
var findGCD = function(nums) {
18+
return gcd(Math.min(...nums), Math.max(...nums));
19+
20+
function gcd(a, b) {
21+
return b === 0 ? a : gcd(b, a % b);
22+
}
23+
};

0 commit comments

Comments
 (0)