Length Of Last Word Leet Code

I submitted my length of last word problem solution and it came an error for " a" but then when I ran " a" as a testcase it accepted it. Any ideas ?
Here is the link to the problem : https://leetcode.com/problems/length-of-last-word
Here is the code
\class Solution {
public:
int lengthOfLastWord(string s) {
if(s.length() ==0 )
{

        return 0;
    }
    string x; 
     s.erase(0, s.find_first_not_of( "\t\n\v\f\r ")); //ltrim
    s.erase(s.find_last_not_of( "\t\n\v\f\r ") + 1);; //rtrim
  printf("%s", s.c_str());
    int len;
 
   

    return len; 
}
    

};

Comments (0)