본문 바로가기
python-algorithm

leetcode 1816. Truncate Sentence

by 무적김두칠 2022. 3. 7.

1
2
3
4
5
6
7
class Solution:
    def truncateSentence(self, s: str, k: int-> str:
        sList=s.split()
        ans=sList[0]
        for i in range(1, min(k,len(sList))):
            ans=ans+' '+sList[i]
        return ans
cs
반응형

댓글