fork download
  1. import bisect
  2.  
  3. def find_port(ports, target):
  4. """
  5. Returns the first integer in ports that equals the target or is greater.
  6. If there is no solution, returns -1.
  7.  
  8. Args:
  9. ports (list): [80, 22, 443, 21]
  10. target (int): 25
  11.  
  12. Returns:
  13. int: The first port number greater than or equal to the target, or -1 if not found.
  14. """
  15. # Find the insertion point for the target in the sorted list
  16. index = bisect.bisect_left(ports, target)
  17.  
  18. # If the target is in the list or there's a port greater than the target, return it
  19. if index != len(ports):
  20. return ports[index]
  21.  
  22. # If no port is greater than or equal to the target, return -1
  23. return
Success #stdin #stdout 0.08s 14068KB
stdin
Standard input is empty
stdout
Standard output is empty