题目描述: 代码: package interview;/** * @author hxw * @create 2025-05-06-8:28 * @Description: 58. 最后一个单词的长度 简单 */public class fifty_eight { public static void main(String[] args) { System.out.println(Solution.lengthOfLastWord("Hello World")); } /** * 目的:给你一个字符串 s,由若干单词组成,单词前后用一些空格字符隔开。返回字符串中 最后一个 单词的长度 * 单词 是指仅由字母组成、不包含任何空格字符的最大子字符串。 * <p> * 思路:空格拆分 */ class Solution { public static int lengthOfLastWord(String s) { String[] str = s.split(" "); return str[str.length - 1].length(); } }}