题目:https://leetcode-cn.com/problems/length-of-last-word/
答案:
public int lengthOfLastWord(String s) {
s = s.trim();
int index = s.lastIndexOf(" ");
if(index<0){
return s.length();
}else{
return s.length()-index-1;
}
}
题目:https://leetcode-cn.com/problems/length-of-last-word/
答案:
public int lengthOfLastWord(String s) {
s = s.trim();
int index = s.lastIndexOf(" ");
if(index<0){
return s.length();
}else{
return s.length()-index-1;
}
}