My simple solution in C++ using istringstream


  • 1
    A
    class Solution {
    public:
        int lengthOfLastWord(const char *s) {
            string word;
            int len=0;
            istringstream stream(s);
            while(stream>>word)
                len=word.size();
            return len;
        }
    };

  • 0
    C

    I think this is a "C++" solution, most other solutions marked as "C++" are really C solution by manipulating pointers.


Log in to reply
 

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