neetcode-gh / leetcode

Leetcode solutions
MIT License
5.55k stars 2.29k forks source link

Update 0058-length-of-last-word.py #3481

Open Zirafnik opened 4 months ago

Zirafnik commented 4 months ago

If I am not mistaken [::-1] creates a new (reversed) string, which would give that solution a space complexity of O(n).

Instead we should just use a backwards iterator.