Reputation: 1
I understand that Arrays.sort()
has a void return type, and that toArray()
has return type is an object, so I did an override by passing in the object that I wanted to see.
How can I see the contents of my Time object?
Sorry if this is a duplicate.
/**
* Definition of Interval:
* public classs Interval {
* int start, end;
* Interval(int start, int end) {
* this.start = start;
* this.end = end;
* }
* }
*/
public class Solution {
/**
* @param intervals: an array of meeting time intervals
* @return: the minimum number of conference rooms required
*/
public int minMeetingRooms(List<Interval> intervals) {
// Write your code here
if (intervals == null || intervals.size() == 0) {
return 0;
}
Arrays.sort(intervals.toArray(new Interval[intervals.size()]), new StartComparator());
int num = 1;
for(int i = 0; i < intervals.size() - 1 ; i++) {
System.out.print(intervals.get(i).toString());
if(intervals.get(i).end >= intervals.get(i + 1).end) {
num++;
}
}
return num;
}
private class StartComparator implements Comparator<Interval> {
@Override
public int compare(Interval a, Interval b) {
return a.start - b.start;
}
}
}
Upvotes: 0
Views: 256
Reputation: 4574
Assuming you are referring to your custom class named Interval
, you could simply override its toString()
method to print debugging info , for example your instance variables start / end :
public String toString() {
return "Start : " + start + " -- End : " + end;
}
Upvotes: 1