LeetCode #58: Length of Last Word | Beginner's Coding Interview

preview_player
Показать описание
0:00 Problem overview
0:42 Split method
1:44 Optimized solution

#leetcode #coding #programming #algorithms
Рекомендации по теме
Комментарии
Автор

Aside from an excellent explanation, the visuals are impeccable. Thank you!!!

jpkeys
Автор

wow brother, love the way you explain things visually

AccerAspire
Автор

Sooperub Algorithm for Simple Sum...Thankyou

vigneshs
Автор

How does the algorithm know we came to an end? or How does it break out of the loop at index 6?

sharukhsm
Автор

solved it with just 1 while loop

def count_last_word_len(s):
total = 0
last_space = True
i = len(s) - 1
while i>=0:
if (s[i] == ' ' and (last_space == True)):
i-=1
elif(s[i] != ' '):
last_space = False
total+=1
i-=1
else:
break
return total
print(count_last_word_len(" fly me to the moon "))

kaeshur_koder