3 ms·
Realistically, you'd walk the list with a visited set and validate you didn't visit a node twice. This would solve your problem in any realistic use case and y
by usaar333 7y ago
Realistically, you'd walk the list with a visited set and validate you didn't visit a node twice.
This would solve your problem in any realistic use case and you'd never even recognize a constant space solution was possible.