Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyuchaogeek committed Jun 2, 2019
1 parent 168273e commit 4ae3a1f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions 0014-最长公共前缀/Swift/LongestCommonPrefix.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ class LongestCommonPrefix {
func longestCommonPrefix(_ strs: [String]) -> String {
var longestPrefix = [Character](), index = 0

guard let firstStr = strs.first else {
guard let _ = strs.first else {
return String(longestPrefix)
}

let firstStrChars = Array(firstStr)
let strsChars = strs.map { Array($0) }

while index < firstStr.count {
let firstStrChars = strsChars.first!

while index < firstStrChars.count {

longestPrefix.append(firstStrChars[index])

Expand Down

0 comments on commit 4ae3a1f

Please sign in to comment.