💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string. If the last word does not exist, return 0. ~~~ public class Solution { public int lengthOfLastWord(String s) { String [] sp = s.split(" "); //for(int i=sp.length;i>=0;i--){ for(int i=sp.length-1;i>=0;i--){ if(sp[i].length()>0) return sp[i].length(); } return 0; } } ~~~