Skip to content

Instantly share code, notes, and snippets.

@KrauserHuang
Created June 14, 2022 00:42
Show Gist options
  • Save KrauserHuang/b272d8890985f5bffcf7502697f302e0 to your computer and use it in GitHub Desktop.
Save KrauserHuang/b272d8890985f5bffcf7502697f302e0 to your computer and use it in GitHub Desktop.
class Solution {
func removeElement(_ nums: [Int], val: Int) -> Int {
// filter可以篩選目標數字,$0代表nums陣列的每一個數字,篩選條件是當數字不等於val則留下,最後回傳剩餘nums的總數
nums = nums.filter { $0 != val }
return nums.count
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment