String58

来源:互联网 发布:淘宝数据监控 编辑:程序博客网 时间:2024/06/06 23:50

Tips:

int index = s.length() - 1;int count = 0; //count the word length//Find the begin letter of the last wordwhile (index >= 0 && s.charAt(index) == ' ')     index--;if (index == -1) //all blanks    return 0;//Start to count the length of the last wordwhile (index >= 0 && s.charAt(index) != ' ') {    count++;    index--;}return count;

If和后面的while可以合并,因为后面的while不执行的话,count还是0

0 0