-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ58
More file actions
24 lines (23 loc) · 653 Bytes
/
Q58
File metadata and controls
24 lines (23 loc) · 653 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution:#first test
def lengthOfLastWord(self, s):
words=''
for i in range(len(s)):
if s[(-1-i)]!=' ':
words = words + s[(-1-i)]
else:
if words!='':
return len(words)
if words!='':
return len(words)
return 0
class Solution:#standard solution
def lengthOfLastWord(self, s):
str = ''
count = 0
for i in s[::-1]:
if str != '' and i==' ':
return count
if i != ' ':
count = count+ 1
str = str + i
return count