-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathInterval.java
56 lines (46 loc) · 1.1 KB
/
Interval.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.fishercoder.common.classes;
/*
* This is a class used by one OJ problem: MeetingRooms
*/
public class Interval implements Comparable<Interval> {
public int start;
public int end;
public Interval() {
start = 0;
end = 0;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Interval)) {
return false;
}
Interval interval = (Interval) o;
if (start != interval.start) {
return false;
}
return end == interval.end;
}
@Override
public int hashCode() {
int result = start;
result = 31 * result + end;
return result;
}
public Interval(int s, int e) {
this.start = s;
this.end = e;
}
@Override
public int compareTo(Interval o) {
int compareStart = o.start;
// ascending order
return this.start - compareStart;
}
@Override
public String toString() {
return "Interval [start=" + start + ", end=" + end + "]";
}
}