Just 5lines of code using STRINGSTREAMS

programming
Tags: #<Tag:0x00007f2420792278>

#1

Comment body goes here.int Solution::lengthOfLastWord(const string A) {
stringstream ss;
ss<<A;
int temp=0;
while(!ss.eof()){
string s;
ss>>s;
if(s.size()) // if stream contains space character we don’t assign its length.
temp=s.size();
}
return temp;
}