Skip to content

Commit ace28db

Browse files
Update 0027-Remove-Element.swift
1 parent 5547ba0 commit ace28db

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

swift/0027-Remove-Element.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
class Solution {
22
func removeElement(_ nums: inout [Int], _ val: Int) -> Int {
3-
// keep track of the count, init to 0
43
var count: Int = 0
54

6-
// (for) go through nums
7-
// if nums[i] !- val
8-
// set nums[count] = nums[i]
9-
// increment count by 1
10-
for i in nums {
11-
if i != val {
12-
nums[count] = i
13-
count += 1
14-
}
5+
for i in nums where i != val {
6+
nums[count] = i
7+
count += 1
158
}
169

17-
// return count
1810
return count
1911
}
2012
}

0 commit comments

Comments
 (0)