Created
June 14, 2022 00:42
-
-
Save KrauserHuang/b272d8890985f5bffcf7502697f302e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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