python写算法题:leetcode: 58. Length of Last Word

    xiaoxiao2025-08-23  6

    class Solution(object): def lengthOfLastWord(self, s): """ :type s: str :rtype: int """ ret=0 lastch = len(s)-1 for _ in xrange(len(s)): if (s[lastch]==' '): lastch-=1 for ind in xrange(lastch+1): if (s[lastch-ind]==' '): return ind return lastch+1

     

    最新回复(0)