79499769

Date: 2025-03-11 05:58:59
Score: 1.5
Natty:
Report link

Use a set instead of an array for storing the visited nodes. Sets have O(1) lookup time, resulting in a total time complexity of O(n) for your algorithm, which is otherwise correct.

As for the statement that "going from node a to b to a isn't a cycle",

This is true if you consider simple graphs only and have to use the same edge twice, in multigraphs you may have more than one edge connecting a and b in which case a-b-a over distinct edges counts as a cycle.

Reasons:
  • No code block (0.5):
  • Low reputation (1):
Posted by: GreenMamba