557. Reverse Words in a String III
Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.
Example 1:
Input: s = "Let's take LeetCode contest"
Output: "s'teL ekat edoCteeL tsetnoc"
Example 2:
Input: s = "Mr Ding"
Output: "rM gniD"
내 코드
class Solution:
def reverseWords(self, s: str) -> str:
word = s.split()
word = [w[::-1] for w in word]
return " ".join(word)
class Solution:
def reverseWords(self, s: str) -> str:
return " ".join([word[::-1] for word in s.split()])'job 인터뷰 > 코테(Matroid) 준비' 카테고리의 다른 글
| Grocery Shopping List 구현 (1) | 2025.04.17 |
|---|---|
| 271. Encode and Decode Strings (0) | 2025.04.17 |
| 239. Sliding Window Maximum ★ (0) | 2025.04.16 |
| Matroid 관련 LeetCode 문제 번호 정리 (0) | 2025.04.15 |
| Matroid 유형 (0) | 2025.04.15 |