题解 | #字符串最后一个单词的长度#
字符串最后一个单词的长度
https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da
// 获取输入的字符串
const str = readline();
const lastWordLength = (str) => {
// 转换为数组,数组最后一个就是目标单词
const arr = str.split(' ');
return arr[arr.length - 1].length
}
console.log(lastWordLength(str));
OPPO公司福利 1133人发布