avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • Resume
  • Archives
  • Categories
  • Photos
  • Music



{{ date }}

{{ time }}

avatar
Siz Long

My name is Siz. I am a computer science graduate student specializing in backend development with Golang and Python, seeking opportunities in innovative tech projects. My personal website is me.longsizhuo.com .Connect with me on LinkedIn: https://www.linkedin.com/in/longsizhuo/.

  • 主页
  • Resume
  • Archives
  • Categories
  • Photos
  • Music

1460.Class ScheduleIV

  2024-01-01        
字数统计: 146字   |   阅读时长: 1min

topic:

img_2.png

[1460]Class ScheduleIV.md

Thought:

一开始的想法是构建有向picture,然后在有向picture中找到queryDoes the two points have a father -son relationship?。
But watchylbAfter the answer,I find that the accessability is faster first。
First traversalprerequirements,Record all the accessibility。
Then triple cycle,Connect all the availability。

i->j->k,ifi->k,Soi->kIt is。

Code:

1
2
3
4
5
6
7
8
9
10
11
class Solution:
def checkIfPrerequisite(self, n: int, prerequisites: List[List[int]], queries: List[List[int]]) -> List[
bool]:
f = [[False] * n for _ in range(n)]
for a, b in prerequisites:
f[a][b] = True
for k in range(n):
for i in range(n):
for j in range(n):
f[i][j] = f[i][j] or (f[i][k] and f[k][j])
return [f[a][b] for a, b in queries]
  • Python
  • answer
  • Priority search
  • In -depth priority search
  • picture
  • Topology

扫一扫,分享到微信

微信分享二维码
1333.Restaurant filter
146.LRU cache
目录
  1. 1. topic:
  2. 2. Thought:
  3. 3. Code:

153 篇 | 133k
次 | 人
这里自动载入天数这里自动载入时分秒
2022-2025 loong loong | 新南威尔士龙龙号