Simplest soln of them all (C++)

int Solution::lengthOfLastWord(const string A) {
    int count = 0;
    int last = A.length()-1;
    for(int i = last; i>=0; i--){
        if (isspace(A[i])) {
            if(isalpha(A[i+1])) break;
            else continue;
        else count++;
    return count;


This line raises IndexOutofBound Exception when run in another language.(I have tried it in java)


Maybe make i > 0 instead of i >= 0.
When i wrote and ran this I didn’t get any errors. I didn’t try any lang other than C++.