# 93. Restore IP Addresses

dfs

```java
class Solution {
    public List<String> restoreIpAddresses(String s) {
        // dfs
        List<String> result = new LinkedList<>();
        searchIp(s, "", result, 1, 0);
        return result;
    }
    
    private void searchIp(String s, String ip, List<String> result, int sectionCount, int start){
        if(sectionCount == 5){
            if(start>=s.length()) result.add(ip.substring(1, ip.length()));
            return;
        }
        
        for(int i = 1; i<=Math.min(4, s.length()-start); i++){
            if(!(i>1 && s.charAt(start)=='0')){
                String str = s.substring(start, start+i);
                // method: int Integer.valueOf(String)
                if (Integer.valueOf(str)<256){
                    // remember: ip+'.'+str generate a new string obj
                    searchIp(s, ip+'.'+str, result, sectionCount+1, start+i);
                }
            }
        }
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ucan.gitbook.io/notes/93.-restore-ip-addresses.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
