Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1574 from kabirdhillon7/patch-3
Browse files Browse the repository at this point in the history
Create 58-Length-of-Last-Word.swift
  • Loading branch information
tahsintunan authored Jan 7, 2023
2 parents 4f3a563 + 945cee7 commit 4f11feb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions swift/0058-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 4f11feb

Please sign in to comment.