diff --git a/swift/58-Length-of-Last-Word.swift b/swift/58-Length-of-Last-Word.swift new file mode 100644 index 000000000..325fe0e77 --- /dev/null +++ b/swift/58-Length-of-Last-Word.swift @@ -0,0 +1,15 @@ +class Solution { + func lengthOfLastWord(_ s: String) -> Int { + var length: Int = 0 + + for c in s.reversed() { + if c != " " { + length += 1 + } else if (length > 0){ + break; + } + } + + return length + } +}