my c++ 3ms solution


  • 0
    D
    class Solution {
    public:
        int lengthOfLastWord(string s) {
            int counter = 0;
            for(int i = 0; i < s.size(); i++) {
                if(!isblank(s[i])) counter = 0;
                while(!isblank(s[i]) && i < s.size()) {
                    i++;
                    counter++;
                }
            }
            return counter;
        }
    };
    

Log in to reply
 

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