Click here to see the full article post
another solution is bit manipulation.
Space complexity is O(1)
time complexity O(n)
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.