Solution


  • 0
    R

    '''

    class Solution {
    public:
    int lengthOfLastWord(string s) {
    int n=s.length();
    int len=0;
    for(int i=0;i<n;){
    if(s[i]==' '){
    while(i<n&&s[i]==' '){
    i++;
    }
    if(i==n)
    break;
    len=0;
    }
    else{
    len++;
    i++;
    }
    }
    return len;
    }
    };

    '''


Log in to reply
 

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