2차원 좌표 평면에 변이 축과 평행한 직사각형이 있습니다. 직사각형 네 꼭짓점의 좌표 [[x1, y1], [x2, y2], [x3, y3], [x4, y4]]가 담겨있는 배열 dots
가 매개변수로 주어질 때, 직사각형의 넓이를 return 하도록 solution 함수를 완성해보세요.
dots
의 길이 = 4dots
의 원소의 길이 = 2dots[i]
의 원소 < 256dots | result |
---|---|
[[1, 1], [2, 1], [2, 2], [1, 2]] | 1 |
[[-1, -1], [1, 1], [1, -1], [-1, 1]] | 4 |
입출력 예 #1
입출력 예 #2
using System;
using System.Linq;
public class Solution {
public int solution(int[,] dots) {
int answer = 0;
int[] x = new int[4];
int[] y = new int[4];
for(int i = 0; i < 4; i++)
{
x[i] = dots[i,0];
y[i] = dots[i,1];
}
answer = (x.Max() - x.Min()) * (y.Max() - y.Min());
return answer;
}
}
출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges