第七章 回溯算法part03
第七章 回溯算法part03
93.复原IP地址 78.子集 90.子集II
93.复原IP地址
题目地址 :
Code ( 复用 了 131.分割回文串 的 代码 , 同时 对 Component 的 处理 方向 、 遍历 ,/ 选取 方式、 添加 条件 进行 了 调整 , 对 Cache 字符串 的 拼接 ,/ 修剪 维护 进行 了 调整 尤其 是 添加 '.' 分隔 符 后 , Component 的 左 边界 下标 可以 快速 提供 字符串 在 修剪 时 需要 的 一部分 长度 信息 与 前段 形成 '.' 的 数量 形成 长度 信息 ) :
class Solution {
public:
struct Struct_Edge_Left_String_Edge_Right
{
int edge_Left ;
string str_SubStr ;
int edge_Right ;
};
vector<string> restoreIpAddresses(string s) {
int length_s = s.length() ;
// 子串 在 这里 可以 重复
// It ' s different
// seed 位 / 发芽 的 位置
// 回文 串 信息 的 建立
vector<vector<Struct_Edge_Left_String_Edge_Right>> vec_Info_SubStr(length_s , vector<Struct_Edge_Left_String_Edge_Right>(0)) ;
// IP 段 的 添加
for(int i = ( length_s - 1 ) ; i >= 0 ; i-- )
{
int edge_Right = i ;
int edge_Left ;
string str_Temp_Cache = "";
//cout<< " i = " << i << endl ;
for(int j = 0 ; j < 3 ; j ++ )
{
edge_Left = i - j ;
//cout<< " j = " << j << endl ;
if( ( i - j ) < 0 )
{
break ;
}
if(s[i - j ] < 0x30 || s[i - j ] >= 0x40 )
{
break ;
}
if(j == 1 && s[i - j ] == '0')
{
str_Temp_Cache = s[ (i - j) ] + str_Temp_Cache ;
continue ;
}
if(j == 2 )
{
if(s[i - j ] == '0')
{
break ;
}