https://leetcode.com/problems/length-of-last-word/
😭做点简单题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
* @param {string} s
* @return {number}
*/
var lengthOfLastWord = function(s) {
let len = 0
let tail = s.length - 1
while (tail >= 0 && s[tail] === ' ') {
tail--
}
while (tail >= 0 && s[tail] !== ' ') {
len++
tail--
}
return len
};