Please solve the programming task below using a self-contained code snippet in a markdown code block.

Write a method to replace all spaces in a string with '%20'. You may assume that the string has sufficient space at the end to hold the additional characters,and that you are given the "true" length of the string. (Note: If implementing in Java,please use a character array so that you can perform this operation in place.)
Please complete the following python code precisely:
```python
class Solution:
    def replaceSpaces(self, S: str, length: int) -> str:
```