Skip to content

Commit d686864

Browse files
committed
最后一个单词的长度
1 parent bbb3aa0 commit d686864

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

length_of_last_word.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
3+
class Solution:
4+
# @param {string} s A string
5+
# @return {int} the length of last word
6+
def lengthOfLastWord(self, s):
7+
# Write your code here
8+
ret, i = 0, len(s) - 1
9+
while i >= 0:
10+
if s[i] != ' ':
11+
ret += 1
12+
elif ret > 0:
13+
break
14+
i -= 1
15+
return ret

0 commit comments

Comments
 (0)