首页 > 代码库 > [LeetCode] Length of Last Word

[LeetCode] Length of Last Word

public class Solution {    public int lengthOfLastWord(String s) {        int lastLength = 0;        int nowLength = 0;                for (int i=0; i<s.length(); i++) {            if(s.charAt(i)==‘ ‘) {                if (nowLength!=0) lastLength=nowLength;                nowLength=0;            }            else                 nowLength++;        }                if (nowLength!=0) lastLength = nowLength;                return lastLength;    }}

 

[LeetCode] Length of Last Word