Skip to content

Commit

Permalink
chore: Rewrite 252 for LeetCode submission
Browse files Browse the repository at this point in the history
  • Loading branch information
euchangxian committed Nov 25, 2024
1 parent ef62e90 commit 1c5759c
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions C++/0252-MeetingRooms/Solution.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
#include <algorithm>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
class Interval {
public:
int start, end;
Interval(int start, int end) : start(start), end(end) {}
};

using namespace std;
class Solution {
public:
bool canAttendMeetings(vector<Interval>& intervals) {
sort(
intervals.begin(), intervals.end(),
[](Interval const& a, Interval const& b) { return a.start < b.start; });
bool canAttendMeetings(std::vector<std::vector<int>>& intervals) {
std::sort(intervals.begin(), intervals.end());

// check for overlaps, i.e., if the previous meeting's ending cuts into the
// current meeting.
for (int i = 1; i < intervals.size(); ++i) {
if (intervals[i].start < intervals[i - 1].end) {
if (intervals[i - 1][1] > intervals[i][0]) {
return false;
}
}
Expand Down

0 comments on commit 1c5759c

Please sign in to comment.