AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
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; } } ~~~