Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Nov 20, 2023
1 parent fad239e commit 80f2474
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions leetcode/58.LengthofLastWord/lengthOfLastWord.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"fmt"
)

func lengthOfLastWord(s string) int {
i := len(s) - 1
for i >= 0 && s[i] == ' ' {
i--
}

j := i
for j >= 0 && s[j] != ' ' {
j--
}

return i - j
}

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

0 comments on commit 80f2474

Please sign in to comment.