Re: [閒聊] 每日leetcode

作者: sustainer123 (caster)   2024-04-01 10:50:50
※ 引述《SecondRun (南爹摳打)》之銘言:
: 58.Length of Last Word
: 找出字串s裡最後面一個字的長度
: 想法:沒有
: public class Solution {
: public int LengthOfLastWord(string s) {
: return s.Trim().Split(' ').Last().Length;
: }
: }
: 我只會EZ
思路:
分割切片算長度
Python Code:
class Solution:
def lengthOfLastWord(self, s: str) -> int:
return len(s.split()[-1])
刷ez紓壓 等等又要寫圖的題目 想死

Links booklink

Contact Us: admin [ a t ] ucptt.com