-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
29 lines (23 loc) · 750 Bytes
/
Solution.java
File metadata and controls
29 lines (23 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public static void main(String[] args){
int p1 = 10;
int p2 = 2;
int[] answer = solution(p1, p2);
for(int e : answer) {
System.out.print(e+" ");
}
}
public static int[] solution(int brown, int yellow){
int sum = brown + yellow;
// at least 3 rows because of '1 <= yellow <= 2,000,000', so at most sum/3 cols.
for( int vertical=3; vertical<=sum/3; vertical++) {
if(sum % vertical == 0){
int horizon = sum / vertical;
if( (vertical-2)*(horizon-2) == yellow ) {
return new int[] {horizon, vertical};
}
}
}
return new int[] {};
}
}