Skip to content

Commit d5da512

Browse files
authored
Merge pull request neetcode-gh#1212 from UdayGarg/58-Length-Of-Last-Word
Create: 58-Length-Of-Last-Word.py
2 parents fd66535 + 7d23521 commit d5da512

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

python/58-Length-Of-Last-Word.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def lengthOfLastWord(self, s: str) -> int:
3+
"""
4+
one shortcut
5+
"""
6+
# return len(s.split()[-1])
7+
c = 0
8+
for i in s[::-1]:
9+
if i == " ":
10+
if c >= 1:
11+
return c
12+
else:
13+
c += 1
14+
return c

0 commit comments

Comments
 (0)