fork download
  1. class Solution {
  2. public:
  3. int lengthOfLastWord(string s) {
  4. int counter=0;
  5. bool found=false;
  6. for(int i=s.length()-1; i>=0; i--){
  7. if(s[i]!=' '){
  8. counter++;
  9. found=true;
  10. }
  11. else if(s[i]==' ' and found){
  12. break;
  13. }
  14. }
  15. return counter;
  16. }
  17.  
  18. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:3:26: error: ‘string’ has not been declared
     int lengthOfLastWord(string s) {
                          ^~~~~~
prog.cpp: In member function ‘int Solution::lengthOfLastWord(int)’:
prog.cpp:6:21: error: request for member ‘length’ in ‘s’, which is of non-class type ‘int’
         for(int i=s.length()-1; i>=0; i--){
                     ^~~~~~
prog.cpp:7:19: error: invalid types ‘int[int]’ for array subscript
             if(s[i]!=' '){
                   ^
prog.cpp:11:24: error: invalid types ‘int[int]’ for array subscript
             else if(s[i]==' ' and found){
                        ^
stdout
Standard output is empty