怒刷 LeetCode 100 道 (58)
來自專欄編程人生
題目
Description:
Given a string s consists of upper/lower-case alphabets and empty space characters , return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined as a character sequence consists of non-space characters only.
Example:
Input: "Hello World"Output: 5
解法
class Solution: def lengthOfLastWord(self, s): """ :type s: str :rtype: int """ ret = 0 no = False for e in s: if e == " ": no = True else: if no: ret = 0 no = False ret += 1 return ret
推薦閱讀:
※今日頭條後台開發實習崗三輪面試面經
※簡單易用的樹莓派平板 帶你快速入門計算機編程
※提高工件加工精度與效率的幾個重要方面,這些你都會了嗎?
※精確的小數-decimal初探
※普通條形圖和棘狀圖坐標軸取值對比