Skip to content

Commit 4b0296a

Browse files
author
แ„‹แ…ตแ„‹แ…งแ†ซแ„‰แ…ฎ
committed
meeting rooms
1 parent c94cd08 commit 4b0296a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package leetcode_study
2+
3+
/*
4+
* ๊ฒน์น˜๋Š” ์‹œ๊ฐ„ ์—†์ด ๋ฏธํŒ…๋ฃธ ์‹œ๊ฐ„์„ ์žก์„ ์ˆ˜ ์žˆ๋Š”์ง€ ํŒ๋‹จํ•˜๋Š” ๋ฌธ์ œ
5+
* ์‹œ์ž‘ ์‹œ๊ฐ„์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ ํ›„ ์ข…๋ฃŒ ์‹œ๊ฐ„๊ณผ ๋‹ค์Œ ๋ฏธํŒ…์˜ ์‹œ๊ฐ„์„ ๋น„๊ตํ•ด ๊ฒน์น˜๋Š” ๋ถ€๋ถ„์ด ์žˆ๋‹ค๋ฉด ์žก์„ ์ˆ˜ ์—†๋Š” ๋ฏธํŒ… ๋ฃธ์œผ๋กœ ํŒ๋‹จ
6+
*
7+
* ์‹œ๊ฐ„ ๋ณต์žก๋„: O(n logn)
8+
* -> intervals null check: O(n)
9+
* -> intervals start ๊ฐ’์œผ๋กœ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌ. Timsort ์‚ฌ์šฉ: O(n logn)
10+
* -> ๊ฒน์น˜๋Š” ๊ตฌ๊ฐ„ ํŒ๋‹จ loop: O(n)
11+
*
12+
* ๊ณต๊ฐ„ ๋ณต์žก๋„: O(n)
13+
* -> ์ •๋ ฌ๋œ ์ƒˆ๋กœ์šด ๋ฏธํŒ… ์‹œ๊ฐ„ ๋ฐฐ์—ด ์ƒ์„ฑ: O(n)
14+
* */
15+
fun canAttendMeetings(intervals: List<Interval?>): Boolean {
16+
if (intervals.isEmpty()) return true
17+
val sortedByList = intervals.filterNotNull().sortedBy { it.start }
18+
for (i in 1 until sortedByList.size) {
19+
if (sortedByList[i - 1].end > sortedByList[i].start) {
20+
return false
21+
}
22+
}
23+
return true
24+
}

0 commit comments

Comments
ย (0)