Split (2) 썸네일형 리스트형 [기타] 릿코드 Easy 1816 'Truncate Sentence' (Python) https://leetcode.com/problems/truncate-sentence/ Truncate Sentence - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 띄어쓰기로 문자열을 구분한다. 순서대로 k 수의 단어를 구한다. 단어별 띄어쓰기 구분으로 문자열을 만든다. class Solution: def truncateSentence(self, s: str, k: int) -> str: s = s.split(' ') return ' '.join(s[:k]) [기타] 릿코드 Easy 557 'Reverse Words in a String III' (Python) https://leetcode.com/problems/reverse-words-in-a-string-iii/ Reverse Words in a String III - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 문자열의 띄어쓰기를 기준으로 각 단어들이 뒤집으면 된다. class Solution: def reverseWords(self, s: str) -> str: answer = '' for i in s.split(): answer += (i[::-1] + '.. 이전 1 다음