In place solution to remove duplicates from a sorted list
One way that might speed up your solution slightly is to only place the value if necessary. Also note that only one of the two if conditions can be true, so just use else. Or even better, since there was a continue in the other case, just don't indent it.

i = 0  #slow-run pointer
for j in range(1, len(nums)):
    if nums[j] == nums[i]: 
        continue 
    # capture the result
    i += 1
    if i != j:
        nums[i] = nums[j] #in place overriden 


You can also save half of the index lookups by iterating over the values. Of course it will need slightly more memory this way.

def removeDuplicates(nums):
    if len(nums) &lt; 2:
        return len(nums)
    i = 0  #slow-run pointer
    for j, value in enumerate(nums):
        if value == nums[i]:
            continue
        # capture the result
        i += 1
        if i != j:
            nums[i] = value # in place overriden 
    return i + 1


This can probably be further sped-up by saving nums[i] in a variable as well.



What is interesting is to see timing comparisons to using the itertools recipe unique_justseen (which I would recommend you use in production if you want to get duplicate free values in vanilla Python):

from itertools import groupby
from operator import itemgetter

def unique_justseen(iterable, key=None):
    "List unique elements, preserving order. Remember only the element just seen."
    # unique_justseen('AAAABBBCCDAABBB') --&gt; A B C D A B
    # unique_justseen('ABBCcAD', str.lower) --&gt; A B C A D
    return map(next, map(itemgetter(1), groupby(iterable, key)))

def remove_duplicates(nums):
    for i, value in enumerate(unique_justseen(nums)):
        nums[i] = value
    return i + 1


For nums = list(np.random.randint(100, size=10000)) they take almost the same time:


removeDuplicates took 0.0023s
remove_duplicates took 0.0026s