赞
踩
题目:
题解:
- class Solution {
- public int lengthOfLastWord(String s) {
- int index = s.length() - 1;
- while (s.charAt(index) == ' ') {
- index--;
- }
- int wordLength = 0;
- while (index >= 0 && s.charAt(index) != ' ') {
- wordLength++;
- index--;
- }
- return wordLength;
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。