Skip to content

Commit 1552d84

Browse files
committed
feat: Add solution for LeetCode problem 252
1 parent fac1fba commit 1552d84

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

meeting-rooms/WhiteHyun.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// 252. Meeting Rooms
3+
// https://leetcode.com/problems/meeting-rooms/description/
4+
// Dale-Study
5+
//
6+
// Created by WhiteHyun on 2024/05/12.
7+
//
8+
9+
10+
/*
11+
Definition of Interval:
12+
class Interval {
13+
var start: Int
14+
var end: Int
15+
init() { start = 0; end = 0; }
16+
init(_ a: Int, _ b: Int) { start = a; end = b }
17+
}
18+
*/
19+
final class Solution {
20+
func canAttendMeetings(_ intervals: [Interval]) -> Bool {
21+
let sortedIntervals = intervals.sorted { lhs, rhs in
22+
lhs.start < rhs.start
23+
}
24+
25+
for i in sortedIntervals.indices.dropFirst() where sortedIntervals[i - 1].end > sortedIntervals[i].start {
26+
return false
27+
}
28+
29+
return true
30+
}
31+
}

0 commit comments

Comments
 (0)