How to improve? My 4ms solution beats only 2.15% cpp submissions....

  • 0
    class Solution {
        int lengthOfLastWord(string s) {
            int n = s.size();
            int count = 0;
            for(int i = n-1; i>=0; i--)
                if(s[i]!=' ') count++;
                else if(count) break;
                else continue;
            return count;

Log in to reply

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