Clearing all Test cases and Edge Cases


  • 0
    V

    class Solution {
    public int lengthOfLastWord(String s) {
    if (s.equals("") || s==null)
    return 0;
    int lastwordlength = 0;
    for (int i=s.length()-1; i>=0; i--) {
    if (s.charAt(i) != ' ')
    lastwordlength++;
    if (s.charAt(i) == ' ' && lastwordlength > 0)
    return lastwordlength;
    }
    return lastwordlength;
    }
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.