Skip to content

Commit 3bc0482

Browse files
committed
add longest words in go
1 parent 011960f commit 3bc0482

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

solutions/go/longest-words.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
8+
func longest(sentence string) string {
9+
longest := ""
10+
words := make([]string, 0)
11+
words = strings.Split(sentence, " ")
12+
13+
for _, word := range words {
14+
if len(longest) < len(word) {
15+
longest = word
16+
}
17+
}
18+
19+
return longest;
20+
}
21+
22+
func main() {
23+
fmt.Println(longest("You are just an old antidisestablishmentarian"))
24+
}

0 commit comments

Comments
 (0)