Skip to content

Commit

Permalink
[Array] refactor code style and simplify solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Yi Gu committed May 4, 2016
1 parent 21886bd commit 24d16e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
9 changes: 3 additions & 6 deletions Array/MoveZeroes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
class MoveZeroes {
func moveZeroes(inout nums: [Int]) {
var zeroIndex = 0
var left = 0
let right = nums.count

while left < right {
if nums[left] != 0 {
_swap(&nums, zeroIndex, left)
for i in 0 ..< nums.count {
if nums[i] != 0 {
_swap(&nums, zeroIndex, i)
zeroIndex += 1
}
left += 1
}
}

Expand Down
6 changes: 1 addition & 5 deletions Array/RemoveElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ class RemoveElement {
func removeElement(inout nums: [Int], _ val: Int) -> Int {
var lastIndex = 0

if nums.count == 0 {
return lastIndex
}

for i in 0...nums.count - 1 {
for i in 0 ..< nums.count {
if nums[i] != val {
nums[lastIndex] = nums[i]
lastIndex += 1
Expand Down

0 comments on commit 24d16e9

Please sign in to comment.