jianglilili / jianglilili/leetcode-
Length of Last Word(最后一个单词的长度)
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
[最后一个单词的长度](https://leetcode-cn.com/problems/length-of-last-word/)
```
class Solution {
//time:2019/12/21
public int lengthOfLastWord(String s) {
//解法一:用trim()去掉首尾部空格
// if(s.length()==0)
// {
// return 0;
// }
// String str=s.trim();
// int count=0;
// for(int i=0;i=0;i--)
// {
// if(s.charAt(i)!=' ')
// {
// count++;
// }else if(count>0)
// {
// return count;
// }
// }
// return count;
//解法三:双指针解法
int end=s.length()-1;
while(end>=0&&s.charAt(end)==' ')
{
end--;
}
int start=end;
while(start>=0&&s.charAt(start)!=' ')
{
start--;
}
return end-start;
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.