2 ms·
Came here to say this, as far as LC questions go, this one is pretty straight forward. OP, the way you come up with a solution like this is practice and more pr
by masterof0 5y ago
Came here to say this, as far as LC questions go, this one is pretty straight forward. OP, the way you come up with a solution like this is practice and more practice, the same way you can solve an equation you never seen before, because you have a set of tools (patterns, "tricks", knowledge, ...) that allows you to come up with a solution. Keep practicing and you will see the progress.
- d--b 5y agoOP meant O(1) in time and space (forgot the space but it’s in the linked article). That solution is O(N) in space.