Urlify
1class Solution:
2 def urlify(self, s, length):
3 res = []
4 for c in s:
5 if c == " ":
6 if res and res[-1] == "%20": continue
7 res.append("%20")
8 else: res.append(c)
9 if res and res[-1] == "%20": res.pop()
10
11 return "".join(res)
12
13sol = Solution()
14print(sol.urlify("Mr John Smith ", 13))
15