forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_1362.java
More file actions
21 lines (20 loc) · 658 Bytes
/
_1362.java
File metadata and controls
21 lines (20 loc) · 658 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.fishercoder.solutions;
public class _1362 {
public static class Solution1 {
public int[] closestDivisors(int num) {
int sqrt = (int) Math.sqrt(num);
int left = sqrt + 1;
int right = sqrt + 1;
long product = left * right;
while (product != (long) (num + 1) && product != (long) (num + 2)) {
if (product < (num + 1)) {
left++;
} else if (product > (num + 2)) {
right--;
}
product = left * right;
}
return new int[]{left, right};
}
}
}