222. Restore IP Addresses (Count)

MediumStringString

Given a string of digits, return the number of valid IPv4 addresses that can be formed by inserting three dots. Each of the four segments must be 0-255 with no leading zeros (except '0' itself).

Input: A quoted digit string.

Output: Integer — number of valid IP addresses.

Examples

Example 1
Input: "25525511135"
Output: 2
Explanation: 255.255.11.135 and 255.255.111.35.
Example 2
Input: "0000"
Output: 1
Explanation: 0.0.0.0.
Example 3
Input: "101023"
Output: 5
Explanation: 5 valid IPs.

Constraints

Asked by

AdobeOracleMicrosoftAmazonMetaGoogle
Solve this problem in the editor →