Re: [閒聊] 每日leetcode
看板Marginalman作者sustainer123 (caster )時間1年前 (2024/04/01 10:50)推噓0(0推 0噓 0→)留言0則, 0人參與討論串85/1548 (看更多)
※ 引述《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紓壓 等等又要寫圖的題目 想死
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.43.132.166 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1711939853.A.B19.html
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 85 之 1548 篇):