Skip to content

Commit 7506ef3

Browse files
committed
Add length-of-last-word
1 parent 82f60ab commit 7506ef3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Easy/length-of-last-word.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Code
2+
====
3+
4+
```go
5+
func lengthOfLastWord(s string) int {
6+
s = strings.Trim(s, " ")
7+
words := strings.Split(s, " ")
8+
return len(words[len(words)-1])
9+
}
10+
```
11+
12+
Solution in mind
13+
================
14+
15+
- Trim all trailing and succeeding white space.
16+
17+
- Split the string on space and return the length of the last word (last element).

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ My collection of leet code problems solved in GoLang!
55

66
| [Easy](#easy) | [Medium](#medium) | [Hard](#hard) |
77
|---------------|-------------------|---------------|
8-
| 15 | 27 | 7 |
8+
| 16 | 27 | 7 |
99

1010
Problems finished
1111
=================
@@ -41,6 +41,8 @@ Easy
4141

4242
- [goat-latin](Easy/goat-latin.md)
4343

44+
- [length-of-last-word](Easy/length-of-last-word.md)
45+
4446
Medium
4547
------
4648

0 commit comments

Comments
 (0)