From 0fe8ec8cf62fd7565551034f0e31a8a57f4c6bd7 Mon Sep 17 00:00:00 2001 From: Square Tsou Date: Tue, 13 Nov 2018 17:39:00 +0800 Subject: [PATCH] Update Solution to 027[python2] - 20ms --- solution/027.Remove Element/Solution.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 solution/027.Remove Element/Solution.py diff --git a/solution/027.Remove Element/Solution.py b/solution/027.Remove Element/Solution.py new file mode 100644 index 0000000000000..7c773fc1225c8 --- /dev/null +++ b/solution/027.Remove Element/Solution.py @@ -0,0 +1,18 @@ +#思路与026一致 + +class Solution(object): + def removeElement(self, nums, val): + if not nums: + return 0 + + newtail = 0 + + for i in range(0, len(nums)): + if nums[i] != val: + nums[newtail] = nums[i] + newtail += 1 + + return newtail + + +