Paste Search Dynamic
Recent pastes
validIPAddresses
  1. def validIPAddresses(string):
  2.     # Write your code here.
  3.     return validIPAddressesRec(string, 3)
  4.  
  5. def validIPAddressesRec(string, remainingDots):
  6.         valids = []
  7.         if len(string) == 0 or remainingDots < 0:
  8.                 return []
  9.         if string[0:2] == "0":
  10.                 return []
  11.         for i in range(1, 4):
  12.                 if int(string[:i]) <= 255:
  13.                         if(len(string[i:])) == 0 and remainingDots == 0:
  14.                                 return [string[:i]]
  15.                         arr = validIPAddressesRec(string[i:], remainingDots - 1)
  16.                         for item in arr:
  17.                                 item = string[:i] + "." + item
  18.                         valids += arr
  19.                        
  20.         print(string, remainingDots, valids)
  21.         return valids
  22.  
  23. print(validIPAddresses("1921680"))
Parsed in 0.004 seconds