← 返回 databricks 的题目列表Find First CIDR Covering an IP
类型:online_judge
Given an IP address and a CIDR list, write a function to find the first CIDR block that can cover the given IP address.
Input:
An IP address as a string, e.g., '192.168.1.1'
A list of CIDRs as strings, e.g., ['192.168.0.0/16', '192.168.1.0/24']
Output:
Return the first CIDR block that covers the given IP. If none exists, return an empty string.
Constraints:
The CIDR list is guaranteed to be non-empty.
The format of IP and CIDRs are guaranteed to be valid.
Example:
Input:
ip = '192.168.1.1'
cidr_list = ['192.168.0.0/16', '192.168.1.0/24']
Output:
'192.168.0.0/16'
Input:
ip = '10.1.2.3'
cidr_list = ['192.168.0.0/16', '192.168.1.0/24']
Output:
'' # empty string
Example
Input
192.168.1.1
192.168.0.0/16
192.168.1.0/24