Class Solution

java.lang.Object
g0001_0100.s0093_restore_ip_addresses.Solution

public class Solution extends Object
93 - Restore IP Addresses.<p>Medium</p> <p>A <strong>valid IP address</strong> consists of exactly four integers separated by single dots. Each integer is between <code>0</code> and <code>255</code> ( <strong>inclusive</strong> ) and cannot have leading zeros.</p> <ul> <li>For example, <code>&quot;0.1.2.201&quot;</code> and <code>&quot;192.168.1.1&quot;</code> are <strong>valid</strong> IP addresses, but <code>&quot;0.011.255.245&quot;</code>, <code>&quot;192.168.1.312&quot;</code> and <code>&quot;[email protected]&quot;</code> are <strong>invalid</strong> IP addresses.</li> </ul> <p>Given a string <code>s</code> containing only digits, return <em>all possible valid IP addresses that can be formed by inserting dots into</em> <code>s</code>. You are <strong>not</strong> allowed to reorder or remove any digits in <code>s</code>. You may return the valid IP addresses in <strong>any</strong> order.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;25525511135&rdquo;</p> <p><strong>Output:</strong> [&ldquo;255.255.11.135&rdquo;,&ldquo;255.255.111.35&rdquo;]</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;0000&rdquo;</p> <p><strong>Output:</strong> [&ldquo;0.0.0.0&rdquo;]</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;1111&rdquo;</p> <p><strong>Output:</strong> [&ldquo;1.1.1.1&rdquo;]</p> <p><strong>Example 4:</strong></p> <p><strong>Input:</strong> s = &ldquo;010010&rdquo;</p> <p><strong>Output:</strong> [&ldquo;0.10.0.10&rdquo;,&ldquo;0.100.1.0&rdquo;]</p> <p><strong>Example 5:</strong></p> <p><strong>Input:</strong> s = &ldquo;101023&rdquo;</p> <p><strong>Output:</strong> [&ldquo;1.0.10.23&rdquo;,&ldquo;1.0.102.3&rdquo;,&ldquo;10.1.0.23&rdquo;,&ldquo;10.10.2.3&rdquo;,&ldquo;101.0.2.3&rdquo;]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>0 <= s.length <= 20</code></li> <li><code>s</code> consists of digits only.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details