Skip to content

Commit e217cce

Browse files
authored
Merge pull request #2050 from a93a/58
Create kotlin/0058-length-of-last-word.kt
2 parents 05c62da + 732c479 commit e217cce

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

kotlin/0058-length-of-last-word.kt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
fun lengthOfLastWord(s: String): Int {
3+
var p = s.length-1
4+
while(s[p].isWhitespace()) p--
5+
var count = 0
6+
while(p >= 0 && !s[p].isWhitespace()){
7+
count++
8+
p--
9+
}
10+
return count
11+
}
12+
}

0 commit comments

Comments
 (0)