Skip to content

Commit

Permalink
Create 58-Length-of-Last-Word.swift
Browse files Browse the repository at this point in the history
Created 58-Length-of-Last-Word.swift
  • Loading branch information
kabirdhillon7 authored Dec 23, 2022
1 parent a68908e commit 16044f5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions swift/58-Length-of-Last-Word.swift
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 16044f5

Please sign in to comment.