1816. 截断句子
为保证权益,题目请参考 1816. 截断句子(From LeetCode).
解决方案1
Python
python
# 1816. 截断句子
# https://leetcode-cn.com/problems/truncate-sentence/
class Solution:
def truncateSentence(self, s: str, k: int) -> str:
return " ".join(s.split(" ")[:k])
1
2
3
4
5
6
2
3
4
5
6