@@ -0,0 +1,1880 @@
+%22%22%22%0AQuestion:%0A    Remove Element%0A%0A    Given an array and a value, remove all instances of that value in place and return the new length.%0A%0A    The order of elements can be changed. It doesn't matter what you leave beyond the new length.%0A%0APerformance:%0A    1. Total Accepted: 78411 Total Submissions: 245469 Difficulty: Easy%0A    2. Your runtime beats 70.75%25 of python submissions.%0A%22%22%22%0A%0A%0Aclass Solution(object):%0A    def removeElement_bad(self, nums, val):%0A        %22%22%22%0A        :type nums: List%5Bint%5D%0A        :type val: int%0A        :rtype: int%0A%0A        OJ (online judge) really remove %60val%60 from %60nums%60, not just return the new length.%0A        %22%22%22%0A        return len(filter(lambda num: num != val, nums))%0A%0A    def removeElement(self, nums, val):%0A        %22%22%22%0A        :type nums: List%5Bint%5D%0A        :type val: int%0A        :rtype: int%0A%0A        need to really remove %60val%60 from %60nums%60, not just return the new length.%0A%0A        refer to #removeElement_from_jw2013%0A        %22%22%22%0A        last_unvisited_element_position = len(nums) - 1%0A        curr_idx = 0%0A%0A        while curr_idx %3C= last_unvisited_element_position:%0A            if nums%5Bcurr_idx%5D == val:%0A                nums%5Bcurr_idx%5D, nums%5Blast_unvisited_element_position%5D = nums%5Blast_unvisited_element_position%5D, nums%5Bcurr_idx%5D%0A                last_unvisited_element_position -= 1%0A                # but curr_idx stays as the same value%0A            else:%0A                curr_idx += 1  # move forward curr_idx%0A        # the rest idxes is how many elements we have keep.%0A        return last_unvisited_element_position + 1%0A%0A    def removeElement_from_jw2013(self, A, elem):%0A        last, i = len(A) - 1, 0%0A        while i %3C= last:%0A            if A%5Bi%5D == elem:%0A                A%5Bi%5D, A%5Blast%5D = A%5Blast%5D, A%5Bi%5D%0A                last -= 1%0A            else:%0A                i += 1%0A        return last + 1%0A%0A%0Aassert Solution().removeElement(%5B4, 5%5D, 4) == 1%0A

Add 27-remove-element.py