58. 最后一个单词的长度 题目链接:https://leetcode.cn/problems/length-of-last-word/description/ Java12345678910111213141516class Solution { public int lengthOfLastWord(String s) { int res = 0; String ss = s.trim(); int n = ss.length(); while(n >= 1) { if (ss.charAt(n-1) != ' ') { res++; n--; } else { break; } } return res; }} leetcode算法题 #字符串 #Java #数组 58. 最后一个单词的长度 https://pisces34.github.io/2024/02/26/leetcode/58/ 发布于 2024年2月26日 许可协议 448. 找到所有数组中消失的数字 上一篇 3038. 相同分数的最大操作数目 I 下一篇