feat: 2025-10-23打卡

This commit is contained in:
asahi
2025-10-23 23:09:19 +08:00
parent f06095ad7e
commit d0478198a9

View File

@@ -0,0 +1,30 @@
/*
* @lc app=leetcode id=58 lang=java
*
* [58] Length of Last Word
*/
// @lc code=start
class Solution {
public int lengthOfLastWord(String s) {
if(s == null || s.isBlank()) {
return 0;
}
int i = s.length() - 1;
while(i >= 0 && s.charAt(i) == ' ') {
i--;
}
int r = 0;
while(i >= 0) {
if(s.charAt(i) != ' ') {
r++;
i--;
} else {
break;
}
}
return r;
}
}
// @lc code=end