Advertisement
ConorB4

Untitled

Oct 19th, 2015
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. # Write a method to replace all spaces in a string with '%20'.
  2.  
  3. def urlifyString(str):
  4.     res = []
  5.     start = False
  6.     str = str.strip() # Removes white space from the beginning and end of the string
  7.     for char in reversed(str):
  8.         if(char == ' '):
  9.             res += '02%'
  10.         else: res += char
  11.     res = ''.join(res[::-1])
  12.     return res
  13.  
  14. print urlifyString("       Mr John Smith           ")
  15.  
  16. # O(n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement