Length of Last Word

2019-05-25 22:49:26 浏览数 (1)

1. Description

2. Solution

代码语言:javascript复制
class Solution {
public:
    int lengthOfLastWord(string s) {
        int length = 0;
        int index = s.find_last_not_of(" ");
        if(index == -1) {
            return length;
        }
        while(index >= 0 && s[index--] != ' ') {
            length  ;
        }
        return length;
    }
};

0 人点赞