Skip to content

Commit

Permalink
optimize code style to Merge Intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
soapyigu committed Apr 11, 2017
1 parent 4ec4f29 commit 10ca4c9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Sort/MergeIntervals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class MergeIntervals {
func merge(intervals: [Interval]) -> [Interval] {
guard intervals.count > 1 else {
guard intervals.count > 0 else {
return intervals
}

Expand All @@ -28,12 +28,11 @@ class MergeIntervals {
}
}

var res = [Interval]()
res.append(intervals[0])
var res = [intervals.first!]

for i in 1 ..< intervals.count {
let last = res[res.count - 1]
let current = intervals[i]
let (last, current) = (res.last!, intervals[i])

if current.start > last.end {
res.append(current)
} else {
Expand Down

0 comments on commit 10ca4c9

Please sign in to comment.