Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

58. Length of Last Word leetcode solution in c++

class Solution {
public:
    int lengthOfLastWord(string s) {
        int n=s.length();
        bool flag=false;
        int cnt=0;
        for(int i=n-1;i>=0;i--)
        {
            if(s[i]>=65&&s[i]<=90||s[i]>=97&&s[i]<=122)
            {
                cnt++;
                flag=true;
            }else
            {
                if(flag)
                {
                    break;
                }
            }
        }
        return cnt;
    }
};
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Length #Last #Word #leetcode #solution
ADD COMMENT
Topic
Name
9+6 =