점 네 개의 좌표를 담은 이차원 배열 dots가 다음과 같이 매개변수로 주어집니다.
주어진 네 개의 점을 두 개씩 이었을 때, 두 직선이 평행이 되는 경우가 있으면 1을 없으면 0을 return 하도록 solution 함수를 완성해보세요.
class Solution {
public int solution(int[][] dots) {
int answer = 0;
for(int i = 0; i < dots.length; i++) {
float grad1 = gradient(dots[i], dots[(i+1)%4]);
float grad2 = gradient(dots[(i+2)%4], dots[(i+3)%4]);
if(grad1 == grad2) answer = 1;
}
return answer;
}
public float gradient(int[] num1, int[] num2) {
float denom = num1[0] - num2[0];
float numer = num1[1] - num2[1];
return numer/denom;
}
}