-
Notifications
You must be signed in to change notification settings - Fork 0
/
Remove Element
42 lines (35 loc) · 989 Bytes
/
Remove Element
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Solution:
def removeElement(self, nums, val):
"""
:type nums: List[int]
:type val: int
:rtype: int
"""
while val in nums:
nums.remove(val)
return len(nums)
def stringToIntegerList(input):
return json.loads(input)
def integerListToString(nums, len_of_list=None):
if not len_of_list:
len_of_list = len(nums)
return json.dumps(nums[:len_of_list])
def main():
import sys
def readlines():
for line in sys.stdin:
yield line.strip('\n')
lines = readlines()
while True:
try:
line = next(lines)
nums = stringToIntegerList(line);
line = next(lines)
val = int(line);
ret = Solution().removeElement(nums, val)
out = integerListToString(nums, len_of_list=ret)
print(out)
except StopIteration:
break
if __name__ == '__main__':
main()