Created
January 19, 2020 12:41
-
-
Save spurscho/596bac7b69f75e67c57670af45796847 to your computer and use it in GitHub Desktop.
27. Remove Element
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: 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