DEV Community

guang
guang

Posted on • Edited on

leetcode 283

i also used double pointer i learned yesterday to solve the problem today. i can't wait to check the time complexity so i submit it without refactor, i still only beat 28% person with complexity n, so i was eager to check solution. i really need refactor before submission, my code is really not clean. but i learned a python syntactic sugar from the other's solution. that's :

nums[i], nums[nonzero] = nums[nonzero], nums[i]

today i checked the solution on YouTube. in my solution i start two pointer from different index so they never point to the same index, in this way, code logic is complicated. in their solution, they start the two pointer both from index 0, so sometimes the two pointer points to the same index and they swap! that's weird but seems no one have any doubt about that. but in this way, the code is neat and clean.

Top comments (0)