알고리즘 코드카타
select x, y, z, (
case when x + y <= z then 'No'
when z + x <= y then 'No'
when y + z <= x then 'No'
else 'Yes'
end
) as triangle
from Triangle;
class Solution {
public int[] solution(int brown, int yellow) {
int[] answer = {3,3};
for (int i = 3; i < brown/2; i++) {
int width = brown / 2 - i + 2;
if (carpet(brown, yellow, width, i)) {
answer[0] = width;
answer[1] = i;
break;
}
}
return answer;
}
public boolean carpet(int brown, int yellow, int width, int i){
int total = brown + yellow;
if (width + i != brown / 2 + 2) {
return false;
}
if (width*i != total){
return false;
}
return true;
}
}