class Solution {
public:
vector<string> ret;
string src;
int len;
unordered_set<string> added;
vector<string> restoreIpAddresses(string s) {
if ( s.empty() ) return ret;
src = s;
len = src.size();
backTrack(,, "");
return ret;
} void backTrack(int pos, int dot_cnt, string substr) {
if ( dot_cnt > ) return;
if ( pos >= len && dot_cnt == ) {
substr.pop_back();
if ( added.find(substr) == added.end() ) {
ret.push_back( substr );
added.insert( substr );
}
return;
}
char buffer[];
int tx = len - pos > ? : len - pos;
for ( int i = ; i <= tx; i++ ) {
string temp = src.substr( pos, i );
int number = atoi( temp.c_str() );
sprintf( buffer, "%d", number );
string str(buffer);
if ( str != temp ) continue;
string newsub = substr + temp + ".";
if ( number >= && number <= ) {
backTrack( pos + i, dot_cnt + , newsub );
}
}
}
};

Leetcode OJ : Restore IP Addresses backtrack暴搜 C++ solution的更多相关文章

  1. leetcode 93. Restore IP Addresses(DFS, 模拟)

    题目链接 leetcode 93. Restore IP Addresses 题意 给定一段序列,判断可能组成ip数的所有可能集合 思路 可以采用模拟或者DFS的想法,把总的ip数分成四段,每段判断是 ...

  2. 【leetcode】Restore IP Addresses

    Restore IP Addresses Given a string containing only digits, restore it by returning all possible val ...

  3. [LeetCode] 93. Restore IP Addresses 复原IP地址

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  4. 【leetcode】Restore IP Addresses (middle)

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  5. leetcode 93 Restore IP Addresses ----- java

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  6. Java for LeetCode 093 Restore IP Addresses

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  7. LeetCode : 93. Restore IP Addresses

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABZ4AAAHUCAYAAAC6Zj2HAAAMFGlDQ1BJQ0MgUHJvZmlsZQAASImVlw

  8. 【LeetCode】93. Restore IP Addresses

    Restore IP Addresses Given a string containing only digits, restore it by returning all possible val ...

  9. LeetCode: Restore IP Addresses 解题报告

    Restore IP Addresses My Submissions Question Solution Given a string containing only digits, restore ...

随机推荐

  1. smarty foreach 最全用法

    <?php$search_condition = "where name like '$foo%' ";$sql = 'select contact_id, name, ni ...

  2. spoj 368

    额   最小生成树 ........ #include <cstdio> #include <cstring> #include <algorithm> using ...

  3. ajax返回正个页面

       

  4. zoj 3329 One Person Game 概率DP

    思路:这题的递推方程有点麻烦!! dp[i]表示分数为i的期望步数,p[k]表示得分为k的概率,p0表示回到0的概率: dp[i]=Σ(p[k]*dp[i+k])+dp[0]*p0+1 设dp[i]= ...

  5. Android 调用系统的拍相程序进行录像

    xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...

  6. UIcollectionView的使用(首页的搭建1)

    今天做一个首页的效果:  首页是用UICollectionView做的.下面我来结合首页的效果介绍一下: 一.创建基类继承自UIViewController 01 创建基类继承自UIViewContr ...

  7. python之高性能网络编程并发框架eventlet实例

    http://blog.csdn.net/mingzznet/article/details/38388299 前言: 虽然 eventlet 封装成了非常类似标准线程库的形式,但线程和eventle ...

  8. javaweb学习总结(四十四)——监听器(Listener)学习

    一.监听器介绍 1.1.监听器的概念

  9. Qt之QtSoap(访问WebService)

    http://blog.csdn.net/u011012932/article/details/51673800

  10. IDirect3DDevice9::GetRenderTargetData

    翻译自DXSDK 将渲染目标数据从设备内存拷贝到系统内存. HRESULT GetRenderTargetData(  [in]  IDirect3DSurface9 *pRenderTarget,  ...