Skip to content

Commit

Permalink
more sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Apr 1, 2024
1 parent c7b0da5 commit d93b8dc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion leetcode/58.LengthofLastWord/lengthOfLastWord.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"strings"
)

func lengthOfLastWord(s string) int {
Expand All @@ -18,7 +19,14 @@ func lengthOfLastWord(s string) int {
return i - j
}

func lengthOfLastWord1(s string) int {
s = strings.TrimSpace(s)
words := strings.Split(s, " ")

return len(words[len(words)-1])
}

func main() {
s := "luffy is still joyboy"
fmt.Println(lengthOfLastWord(s))
fmt.Println(lengthOfLastWord1(s))
}

0 comments on commit d93b8dc

Please sign in to comment.