Solve 58. Length of Last Word
This commit is contained in:
parent
cb08f3ce4e
commit
fa8bbdeecb
9
python/58_length_of_last_word.py
Normal file
9
python/58_length_of_last_word.py
Normal file
@ -0,0 +1,9 @@
|
||||
class Solution:
|
||||
def lengthOfLastWord(self, s: str) -> int:
|
||||
end = len(s)-1
|
||||
while end >= 0 and s[end] == " ":
|
||||
end -= 1
|
||||
i = end
|
||||
while i >= 0 and s[i] != " ":
|
||||
i -= 1
|
||||
return end-i
|
Loading…
Reference in New Issue
Block a user