Practice/Meta/Leetcode 468. Validate IP Address
CodingMust
You are building a network configuration validator. Given a string representing a potential IP address, determine whether it's a valid IPv4 address, a valid IPv6 address, or neither.
Return one of three strings:
"IPv4" if the input is a valid IPv4 address"IPv6" if the input is a valid IPv6 address"Neither" if the input is not a valid IP address of either typeIPv4 Address Rules:
IPv6 Address Rules:
Example 1:
Input: queryIP = "172.16.254.1" Output: "IPv4" Explanation: This string represents a valid IPv4 address with four octets, all within the valid range of 0-255.
Example 2:
Input: queryIP = "2001:0db8:85a3:0:0:8A2E:0370:7334" Output: "IPv6" Explanation: This is a valid IPv6 address with eight colon-separated groups of hexadecimal digits.
Example 3:
Input: queryIP = "192.168.1.00" Output: "Neither" Explanation: The last octet "00" has a leading zero, which violates IPv4 rules.
Example 4:
Input: queryIP = "02001:0db8:85a3:0:0:8A2E:0370:7334" Output: "Neither" Explanation: The first group has 5 characters, exceeding the maximum of 4 allowed in IPv6.
Example 5:
Input: queryIP = "192.168.1.1." Output: "Neither" Explanation: There's a trailing dot at the end, making it invalid.