One Line Swift Solution


  • 0
    Y
    func lengthOfLastWord(_ s: String) -> Int {
            return (s.trimmingCharacters(in: .whitespaces).components(separatedBy: " ").last?.characters.count)!
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.