Search
 
SCRIPT & CODE EXAMPLE
 

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;
    }
};
Comment

PREVIOUS NEXT
Code Example
Cpp :: overload of << c++ 
Cpp :: sorting using comparator in c++ 
Cpp :: how to append to a vector c++ 
Cpp :: long to string cpp 
Cpp :: prisma client 
Cpp :: c++ average 
Cpp :: 3d projection onto 2d plane algorithm 
Cpp :: how to convert ascii to char in cpp 
Cpp :: how to get the time in c++ as string 
Cpp :: function in struct c++ 
Cpp :: Setting a number of decimals on a float on C++ 
Cpp :: sleep in c++ 
Cpp :: odd numbers 1 to 100 
Cpp :: how to calculate bitwise xor c++ 
Cpp :: cpp while 
Cpp :: pure virtual function in c++ 
Cpp :: sum of a matrix c++ 
Cpp :: how to cout in c++ 
Cpp :: how to make a comment in c++ 
Cpp :: how to generate number in c++ 
Cpp :: c++ pointers and functions 
Cpp :: C++ String Compare Example 
Cpp :: inheritance example in C plus plus 
Cpp :: variables in c++ 
Cpp :: add matic mainnet to metamask mobile 
Cpp :: long long int range c++ 
Cpp :: c++ open webpage 
Cpp :: what is a variable in cpp 
Cpp :: store array in vector 
Cpp :: bit++ codeforces in c++ 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =