File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You canโt perform that action at this time.
0 commit comments