We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see ourdocumentation.
There was an error while loading.Please reload this page.
原题链接
过滤掉末尾空格后,反向遍历字符串,并使用 count 计数,再次遇到空格时结束。
constlengthOfLastWord=function(s){if(s.length===0)return0letcount=0for(leti=s.length-1;i>=0;i--){if(s.charAt(i)===' '){if(count===0)continuebreak}count++}returncount}