We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 66d1664 commit c3b51f1Copy full SHA for c3b51f1
03-Remove Element.py
@@ -0,0 +1,30 @@
1
+'''
2
+Example 1:
3
+
4
+Input: nums = [3,2,2,3], val = 3
5
+Output: 2, nums = [2,2,_,_]
6
+Explanation: Your function should return k = 2, with the first two elements of nums being 2.
7
+It does not matter what you leave beyond the returned k (hence they are underscores).
8
9
+Example 2:
10
11
+Input: nums = [0,1,2,2,3,0,4,2], val = 2
12
+Output: 5, nums = [0,1,4,0,3,_,_,_]
13
+Explanation: Your function should return k = 5, with the first five elements of nums containing 0, 0, 1, 3, and 4.
14
+Note that the five elements can be returned in any order.
15
16
17
18
+def removeElement(nums, val):
19
+ for i in range(nums.count(val)):
20
+ nums.pop(nums.index(val))
21
+ return len(nums)
22
23
+nums = [3,2,2,3]
24
+print(removeElement(nums, 3))
25
26
+nums = [0,1,2,2,3,0,4,2]
27
+print(removeElement(nums, 2))
28
29
+nums = []
30
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments