backtracking:

Restore Ip Addresses

Given a string containing only digits, restore it by returning all possible valid IP address combinations. Example Input: "25525511135" Output: ["255.255.11.135", "255.255.111.35"] Solution class Solution: def restoreIpAddresses(self, s: str) -> List[str]: results = [] self.backtrack(results, s, 0, "", 0) return results def backtrack(self, results, s, start, partial, segment_count): # pruning for performance improvement if (4 - segment_count) * 3 < len(s) - start or (4 - segment_count) > len(s) - start: return # base case goal if start == len(s) and segment_count == 4: results.

by lek tin dfs backtracking in "algorithm" access_time 1-min read