

별로 특이사항 없길래 안 올리려다가, 프로그래머스 0레벨 중 정답률이 두번째로 낮아서 그냥 썼다.
평행=두 선분의 기울기가 같다 인데, 중요한건 int값은 나눗셈에서 버림처리가 될 수 있기에...double로 처리해줘야한다.
class Solution {
public int solution(int[][] dots) {
int answer = 0;
if (slope(dots[0], dots[1])==slope(dots[2],dots[3])) {
answer = 1;
} else if (slope(dots[0], dots[2])==slope(dots[1],dots[3])) {
answer = 1;
} else if (slope(dots[0], dots[3])==slope(dots[1],dots[2])) {
answer = 1;
}
return answer;
}
public double slope(int[] a, int[] b) {
return (a[0]-b[0])*1.0/(a[1]-b[1]);
}
}'프로그래머스 문제풀이 > Level 0' 카테고리의 다른 글
| 치킨쿠폰 (자바, Java) (0) | 2022.12.14 |
|---|---|
| 다음에 올 숫자 (자바, Java) (0) | 2022.12.13 |
| 다항식 더하기 (자바, Java) (0) | 2022.12.11 |
| 숨어있는 숫자의 덧셈 (2) (자바, Java) (0) | 2022.12.11 |
| 잘라서 배열로 저장하기 (자바, Java) (0) | 2022.12.11 |