Skip to content

Instantly share code, notes, and snippets.

@spurscho
Created January 19, 2020 12:41
Show Gist options
  • Select an option

  • Save spurscho/596bac7b69f75e67c57670af45796847 to your computer and use it in GitHub Desktop.

Select an option

Save spurscho/596bac7b69f75e67c57670af45796847 to your computer and use it in GitHub Desktop.
27. Remove Element
class Solution {
func removeElement(_ nums: inout [Int], _ val: Int) -> Int {
guard nums.count > 0 else {
return 0
}
var idx: Int = 0
while true {
if idx == nums.count {
break
}
if nums[idx] == val {
nums.remove(at: idx)
} else {
idx += 1
}
}
return nums.count
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment