Skip to content

Commit e40ed06

Browse files
committed
Create 0058-Length-of-Last-Word.go
1 parent c901198 commit e40ed06

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

go/0058-Length-of-Last-Word.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
func lengthOfLastWord(s string) int {
2+
l := 0
3+
4+
for i := len(s) - 1; i >= 0; i-- {
5+
if s[i] == ' ' {
6+
if l >= 1 {
7+
return l
8+
}
9+
} else {
10+
l++
11+
}
12+
}
13+
14+
return l
15+
}å

0 commit comments

Comments
 (0)