"""
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.)

Example 1:

Input: "Mr John Smith ", 13
Output: "Mr%20John%20Smith"
Example 2:

Input: "               ", 5
Output: "%20%20%20%20%20"
 

Note:

0 <= S.length <= 500000

来源：力扣（LeetCode）
链接：https://leetcode-cn.com/problems/string-to-url-lcci
著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。
"""


class Solution:
    def replaceSpaces(self, S: str, length: int) -> str:
        return S[:length].replace(' ', '%20')

Slt = Solution()
S = "Mr John Smith "
length = 13
print(Slt.replaceSpaces(S, length))

S = "               "
length = 5
Slt = Solution()
print(Slt.replaceSpaces(S, length))
05d082ec3dd1ff1e13a75407f70607cf892d7864
<mask token>


class Solution:
    <mask token>


<mask token>

<mask token>


class Solution:

    def replaceSpaces(self, S: str, length: int) ->str:
        return S[:length].replace(' ', '%20')


<mask token>

<mask token>


class Solution:

    def replaceSpaces(self, S: str, length: int) ->str:
        return S[:length].replace(' ', '%20')


<mask token>
print(Slt.replaceSpaces(S, length))
<mask token>
print(Slt.replaceSpaces(S, length))

<mask token>


class Solution:

    def replaceSpaces(self, S: str, length: int) ->str:
        return S[:length].replace(' ', '%20')


Slt = Solution()
S = 'Mr John Smith '
length = 13
print(Slt.replaceSpaces(S, length))
S = '               '
length = 5
Slt = Solution()
print(Slt.replaceSpaces(S, length))

"""
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.)

Example 1:

Input: "Mr John Smith ", 13
Output: "Mr%20John%20Smith"
Example 2:

Input: "               ", 5
Output: "%20%20%20%20%20"
 

Note:

0 <= S.length <= 500000

来源：力扣（LeetCode）
链接：https://leetcode-cn.com/problems/string-to-url-lcci
著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。
"""


class Solution:
    def replaceSpaces(self, S: str, length: int) -> str:
        return S[:length].replace(' ', '%20')

Slt = Solution()
S = "Mr John Smith "
length = 13
print(Slt.replaceSpaces(S, length))

S = "               "
length = 5
Slt = Solution()
print(Slt.replaceSpaces(S, length))