File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change
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).
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ My collection of leet code problems solved in GoLang!
5
5
6
6
| [ Easy] ( #easy ) | [ Medium] ( #medium ) | [ Hard] ( #hard ) |
7
7
| ---------------| -------------------| ---------------|
8
- | 15 | 27 | 7 |
8
+ | 16 | 27 | 7 |
9
9
10
10
Problems finished
11
11
=================
41
41
42
42
- [ goat-latin] ( Easy/goat-latin.md )
43
43
44
+ - [ length-of-last-word] ( Easy/length-of-last-word.md )
45
+
44
46
Medium
45
47
------
46
48
You can’t perform that action at this time.
0 commit comments