Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2050 from a93a/58
Browse files Browse the repository at this point in the history
Create kotlin/0058-length-of-last-word.kt
  • Loading branch information
a93a authored Jan 16, 2023
2 parents 05c62da + 732c479 commit e217cce
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kotlin/0058-length-of-last-word.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution {
fun lengthOfLastWord(s: String): Int {
var p = s.length-1
while(s[p].isWhitespace()) p--
var count = 0
while(p >= 0 && !s[p].isWhitespace()){
count++
p--
}
return count
}
}

0 comments on commit e217cce

Please sign in to comment.