Skip to content

Commit e620caa

Browse files
authored
Create Number of Common Factors.java
1 parent 78c258d commit e620caa

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Easy/Number of Common Factors.java

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int commonFactors(int a, int b) {
3+
int count = 0;
4+
int minNum = Math.min(a, b);
5+
for (int i = 1; i <= minNum / 2; i++) {
6+
if (a % i == 0 && b % i == 0) {
7+
count++;
8+
}
9+
}
10+
return count + (a % minNum == 0 && b % minNum == 0 ? 1 : 0);
11+
}
12+
}

0 commit comments

Comments
 (0)