C++ Solution


  • 0
    W
    class Solution {
    public:
        int lengthOfLastWord(string s) {
            int ret=0;
            for(string::reverse_iterator it=s.rbegin();it!=s.rend();it++){
                if(*it!=' ') ret++;
                else if(ret!=0) break;
            }
            return ret;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.