Skip to content

Commit 7bfb653

Browse files
committed
Add solution #2427
1 parent ccb1c2b commit 7bfb653

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
2099|[Find Subsequence of Length K With the Largest Sum](./2099-find-subsequence-of-length-k-with-the-largest-sum.js)|Medium|
282282
2114|[Maximum Number of Words Found in Sentences](./2114-maximum-number-of-words-found-in-sentences.js)|Easy|
283283
2129|[Capitalize the Title](./2129-capitalize-the-title.js)|Easy|
284+
2427|[Number of Common Factors](./2427-number-of-common-factors.js)|Easy|
284285

285286
## License
286287

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* 2427. Number of Common Factors
3+
* https://leetcode.com/problems/number-of-common-factors/
4+
* Difficulty: Easy
5+
*
6+
* Given two positive integers a and b, return the number of common factors of a and b.
7+
*
8+
* An integer x is a common factor of a and b if x divides both a and b.
9+
*/
10+
11+
/**
12+
* @param {number} a
13+
* @param {number} b
14+
* @return {number}
15+
*/
16+
var commonFactors = function(a, b) {
17+
let count = 0;
18+
for (let i = Math.min(a, b); i > 0; i--) {
19+
if (a % i === 0 && b % i === 0) count++;
20+
}
21+
return count;
22+
};

0 commit comments

Comments
 (0)