직사각형 넓이 구하기

han.user();·2023년 4월 7일
0

프로그래머스

목록 보기
48/87
post-thumbnail

class Solution {
    public int solution(int[][] dots) {
        int answer = 0;

        int xMin = Integer.MAX_VALUE;
        int xMax = Integer.MIN_VALUE;
        int yMin = Integer.MAX_VALUE;
        int yMax = Integer.MIN_VALUE;

        for (int i = 0; i < dots.length; i++) {
            int x = dots[i][0];
            int y = dots[i][1];
            xMin = Math.min(xMin, x);
            xMax = Math.max(xMax, x);
            yMin = Math.min(yMin, y);
            yMax = Math.max(yMax, y);
        }
        int gapX = Math.abs(xMax - xMin);
        int gapY = Math.abs(yMax - yMin);

        answer = gapX * gapY;
        return answer;
    }
}
profile
I'm still hungry.

0개의 댓글