[Java] Clean code
Clean Code means clear mind. I love clean code.\n\nclass ExamRoom {\n    \n    private static class Interval implements Comparable<Interval> {\n        private 
Clean Code means clear mind. I love clean code.\n```\nclass ExamRoom {\n    \n    private static class Interval implements Comparable<Interval> {\n        private final int start;\n        private final int end;\n        private final int length;\n        private Interval(int start, int end, int length) {\n            this.start = start;\n            this.end = end;\n            this.length = length;\n        }\n        @Override\n        public int compareTo(Interval that) {\n            if (this.length == that.length) {\n                return this.start - that.start;\n            } else {\n                return that.length - this.length;\n            }\n        }\n    }\n    \n    private final PriorityQueue<Interval> intervals;\n    private final int slotCount;\n\n    public ExamRoom(int N) {\n        this.intervals = new PriorityQueue<>();\n        this.slotCount = N;\n        intervals.offer(new Interval(-1, N, N));\n    }\n    \n    public int seat() {\n        if (intervals.isEmpty()) {\n            return -1;\n        }\n        Interval curr = intervals.poll();\n        if (curr.start == -1) {\n            intervals.offer(new Interval(0, curr.end, curr.length - 1));\n            return 0;\n        } else if (curr.end == slotCount) {\n            intervals.offer(new Interval(curr.start, slotCount - 1, curr.length - 1));\n            return slotCount - 1;\n        } else {\n            int seat = curr.start + (curr.end - curr.start) / 2;\n            intervals.offer(new Interval(curr.start, seat, (seat - curr.start) / 2));\n            intervals.offer(new Interval(seat, curr.end, (curr.end - seat) / 2));\n            return seat;\n        }\n    }\n    \n    public void leave(int p) {\n        Interval prev = null;\n        Interval curr = null;\n        for (Interval interval : intervals) {\n            if (interval.end == p) {\n                prev = interval;\n            }\n            if (interval.start == p) {\n                curr = interval;\n            }\n        }\n        if (prev == null && curr != null) {\n            intervals.remove(curr);\n            intervals.offer(new Interval(-1, curr.end, curr.end - curr.start));\n        } else if (prev != null && curr == null) {\n            intervals.remove(prev);\n            intervals.offer(new Interval(prev.start, slotCount, prev.end - prev.start));\n        } else {\n            intervals.remove(curr);\n            intervals.remove(prev);\n            if (prev.start == -1 || curr.end == slotCount) {\n                intervals.offer(new Interval(prev.start, curr.end, curr.end - prev.start));\n            } else {\n                intervals.offer(new Interval(prev.start, curr.end, (curr.end - prev.start) / 2));\n            }\n        }\n    }\n}\n\n/**\n * Your ExamRoom object will be instantiated and called as such:\n * ExamRoom obj = new ExamRoom(N);\n * int param_1 = obj.seat();\n * obj.leave(p);\n */\n```
[]