Skip to content

Commit d1643bb

Browse files
committedOct 30, 2019
Add code for leetcode No.58.
1 parent 43afb18 commit d1643bb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
 

Diff for: ‎leetcode-058/leetcode058.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def lengthOfLastWord(self, s: str) -> int:
3+
newStr = s.strip()
4+
lastSpacePos = newStr.rfind(' ')
5+
if lastSpacePos == -1:
6+
return len(newStr)
7+
else:
8+
return len(newStr) - lastSpacePos - 1
9+
10+
sol = Solution()
11+
print(sol.lengthOfLastWord('Hello my baby'))

0 commit comments

Comments
 (0)