Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leetcode 第231场周赛题解 #29

Open
utterances-bot opened this issue Mar 7, 2021 · 2 comments
Open

Leetcode 第231场周赛题解 #29

utterances-bot opened this issue Mar 7, 2021 · 2 comments

Comments

@utterances-bot
Copy link

Leetcode 第231场周赛题解 | CP Wiki

lucifer1004的CP笔记

https://cp-wiki.vercel.app/tutorial/leetcode/WC231/

Copy link

codelh7 commented Mar 7, 2021

想请教下大佬,21-28行的时间复杂度怎么计算的呀?看上去套了三重循环,不太会分析呀

@lucifer1004
Copy link
Owner

@codelh7 注意所有的groups[i]最多有N个元素,所以最内层循环的执行次数最多是N次。

这种分析就类似于图的遍历:

for (int u = 0; u < n; ++u) {
  for (int v : adj[u]) {
    // do something...
  }
}

看上去是两层循环,实际上内层执行的总次数为O(E)次。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants