Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int lengthOfLastWord(string s) {
- int len = 0, tail = s.length() - 1;
- while (tail >= 0 && s[tail] == ' ') tail--;
- while (tail >= 0 && s[tail] != ' ') {
- len++;
- tail--;
- }
- return len;
- }
- };
Add Comment
Please, Sign In to add comment