---
# System prepended metadata

title: 557. Reverse Words in a String III

---

# 557. Reverse Words in a String III

https://leetcode.com/problems/reverse-words-in-a-string-iii/


# 思路

1. 注意邊際問題，用count去解決。


```python=
class Solution:
    def reverseWords(self, s: str) -> str:
        string=""
        num=len(s.split(" "))
        count=0 
        for i in s.split(" "): 
            string+=(i[::-1]) 
            
            count+=1 
            if num==count:
                break
            string+=" "
        return string 
            
```