Skip to content

Latest commit

 

History

History
33 lines (30 loc) · 763 Bytes

File metadata and controls

33 lines (30 loc) · 763 Bytes
title seoTitle description toc tags categories date lastMod featuredImage weight
58. Length of Last Word
LeetCode 58. Length of Last Word | Python solution and explanation
58. Length of Last Word
true
Algorithms
LeetCode
2024-01-01
2024-01-01
58

LeetCode problem 58

class Solution:
    def lengthOfLastWord(self, s: str) -> int:
        i = len(s) - 1
        while i >= 0 and s[i] == ' ':
            i -= 1
        j = i
        while j >= 0 and s[j] != ' ':
            j -= 1
        return i - j
class Solution:
    def lengthOfLastWord(self, s: str) -> int:
        ar = s.split()
        return len(ar[-1])