[leetcode] Restore IP Addresses
Restore IP Addresses Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given “25525511135”, return [“255.255.11.135”, “255.255.111.35”]. (Order does not matter) tag: backtracking, string 花了我好久才搞通这题! 其实大方向是对的,带剪枝的回溯算法。先一个个插dot进去,发现不行后再返回上一层,逐个测试。 有三个点需要注意: 1. 传参数时,result是要随时被更改的,所以传参时要传它的引用。即使我是调用它的push_back()函数,也需要传引用,这个好奇怪。 2. substr的参数是(index, count)表示取[index, index + cout)的子字符串。开始我以为是[start, end)。结果改了好久,在本地上cout才测试出来。 3. stoi不能转换过长的字符串,否则会报RUN TIME ERROR 错误。所以我在stoi函数前,加了s.size() […]