题解 | #字符串最后一个单词的长度#
字符串最后一个单词的长度
http://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da
const line = readline();
function getLastWordLength(str) {
let i = str.length - 1;
while (i > -1) {
if (str[i] === ' ') break;
i -= 1;
}
return str.length - 1 - i;
}
console.log(getLastWordLength(line));
