[코테 풀이] Widest Vertical Area Between Two Points Containing No Points

시내·2024년 6월 11일
0

Q_1637) Widest Vertical Area Between Two Points Containing No Points

출처 : https://leetcode.com/problems/widest-vertical-area-between-two-points-containing-no-points/

Given n points on a 2D plane where points[i] = [xi, yi], Return the widest vertical area between two points such that no points are inside the area.

A vertical area is an area of fixed-width extending infinitely along the y-axis (i.e., infinite height). The widest vertical area is the one with the maximum width.

Note that points on the edge of a vertical area are not considered included in the area.

class Solution {
    public int maxWidthOfVerticalArea(int[][] points) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        for (int q = 0; q < points.length; q++) {
            arrayList.add(points[q][0]);
        }
        Collections.sort(arrayList);
        int max = 0;
        for (int i = 0; i < arrayList.size() - 1; i++) {
            if (max < arrayList.get(i + 1) - arrayList.get(i)) {
                max = arrayList.get(i + 1) - arrayList.get(i);
            }
        }
        return max;
    }

}
profile
contact 📨 ksw08215@gmail.com

0개의 댓글