Practice Validate IP Address
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Classify queryIP as "IPv4", "IPv6", or "Neither" using these rules. IPv4 has exactly four nonempty decimal components separated by periods. Each component is an integer from 0 through 255 and has no leading zero unless it is exactly "0". IPv6 has exactly eight nonempty components separated by colons. Each component has one to four hexadecimal characters: 0–9, a–f, or A–F. Leading zeros are permitted in IPv6 components. This problem requires all eight IPv6 components explicitly; an empty component or "::" abbreviation is invalid.
Source: Validate IP Address on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
queryIP = "172.16.254.1"
"IPv4"
# Example 2
queryIP = "2001:0db8:85a3:0:0:8A2E:0370:7334"
"IPv6"
# Example 3
queryIP = "256.256.256.256"
"Neither"
Constraints
Related LeetCode Problems
Practice more problems similar to Validate IP Address.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.