活跃农民
- 积分
- 876
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2011-7-28
- 最后登录
- 1970-1-1
|
注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
参考:https://www.1point3acres.com/bbs/thread-739042-1-1.html第一问基本上就是LC上的course schedule,第二问应该怎么做?
第一问:
一堆课,找出上课顺序里,中间的那门课,只有一种正确的顺序,并且每个课只会对应另外一个prereq
比如
["Data Structures", "Algorithms"],
["COBOL", "Networking"],
["Algorithms", "COBOL"],
"Data Structures"->"Algorithms" -> "COBOL"-> "Networking"
返回 “Algorithms"
第二问:
/*
有多种track,返回所有path里的中间那门课
Sample input 1:
all_courses_1 = [
["Logic", "COBOL"],
["Data Structures", "Algorithms"],
["Creative Writing", "Data Structures"],
["Algorithms", "COBOL"],
["Intro to Computer Science", "Data Structures"],
["Logic", "Compilers"],
["Data Structures", "Logic"],
["Graphics", "Networking"],
["Networking", "Algorithms"],
["Creative Writing", "System Administration"],
["Databases", "System Administration"],
["Creative Writing", "Databases"],
["Intro to Computer Science", "Graphics"],
]
Sample output 1 (in any order):
["Data Structures", "Networking", "Creative Writing", "Databases"]
All paths through the curriculum (midpoint *highlighted*):
Intro to C.S. -> Graphics -> *Networking* -> Algorithms -> Cobol
Intro to C.S. -> *Data Structures* -> Algorithms -> COBOL
Intro to C.S. -> *Data Structures* -> Logic -> COBOL
Intro to C.S. -> *Data Structures* -> Logic -> Compiler
Creative Writing -> *Databases* -> System Administration
*Creative Writing* -> System Administration
Creative Writing -> *Data Structures* -> Algorithms -> COBOL
Creative Writing -> *Data Structures* -> Logic -> COBOL
Creative Writing -> *Data Structures* -> Logic -> Compilers
Visual representation:
____________ ______________
| | | |
| Graphics | | Networking |
---->|__________|--->|____________|
| |
| |
| | ______________
____________ | | | |
| | | ______________ >->| Algorithms |--\ _____________
| Intro to | | | | / |____________| \ | |
| C.S. |---+ | Data | / >-->| COBOL |
|__________| \ | Structures |--+ ______________ / |___________|
>->|____________| \ | | /
____________ / \-->| Logic |-+ _____________
| | / ______________ |____________| \ | |
| Creative | / | | \--->| Compilers |
| Writing |-+----->| Databases | |___________|
|__________| \ |____________|-\ _________________________
\ \ | |
\--------------------+-->| System Administration |
|_______________________|
Sample input 2:
all_courses_2 = [
["Course_3", "Course_7"],
["Course_0", "Course_1"],
["Course_1", "Course_2"],
["Course_2", "Course_3"],
["Course_3", "Course_4"],
["Course_4", "Course_5"],
["Course_5", "Course_6"],
]
Sample output 2 (in any order):
["Course_2", "Course_3"]
Complexity analysis variables:
n: number of pairs in the input
*/
|
上一篇: 也来分享我的Notion刷题记录,总结归纳为导向,而不是计划导向下一篇: leetcode 刷的上火
|