93.Restore IP Addresses

Medium

617237FavoriteShare

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"]
Accepted 134,897  Submissions 433,902
class Solution {
public:
    vector<string> restoreIpAddresses(string s) {
        vector<string> result;
        string ip;
        dfs(s,,,ip,result); //paras:string s,start index of s,step(from0-3),intermediate ip,final result
        return result;
    }
    void dfs(string s,int start,int step,string ip,vector<string>& result){
        ){
            ip.erase(ip.end()-); //remove the last '.' from the last decimal number
            result.push_back(ip);
            return;
        }
        -step)*) return;
        -step)) return;
        ;
        ;i++){
            num=num*+(s[i]-');
            ){
                ip+=s[i];
                dfs(s,i+,step+,ip+'.',result);
            }
            ) break;
        }
    }
};
// zjchenRice

93.Restore IP Addresses(M)的更多相关文章

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

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

  2. 93. Restore IP Addresses

    题目: Given a string containing only digits, restore it by returning all possible valid IP address com ...

  3. 【LeetCode】93. Restore IP Addresses

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

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

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

  5. 【一天一道LeetCode】#93. Restore IP Addresses

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

  6. 93. Restore IP Addresses产生所有可能的ip地址

    [抄题]: Given a string containing only digits, restore it by returning all possible valid IP address c ...

  7. LeetCode OJ 93. Restore IP Addresses

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

  8. 93. Restore IP Addresses(dfs)

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

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

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

随机推荐

  1. 头部banner根据网址高亮

    $(function(){ var urlstr = location.href; $(".nav li a").each(function () { if ((urlstr + ...

  2. 在 Angular 8 中,我们可以期待些什么

    转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者. 本文由葡萄城翻译并发布 --- Angular 作为一款优秀的前端框架,自诞生之日起,就致力于面向前端开发者 ...

  3. 章节十、4-CSS Classes---用多个CSS Classes定位元素

    以下演示操作以该网址中的输入框为例:https://learn.letskodeit.com/p/practice 一.使用input[class=inputs]验证元素是否唯一 注意:使用“clas ...

  4. Linux(CentOS 7)安装测试mysql5.6服务

    1.rpm -qa | grep mysql,查看原系统中是否有已经安装得mysql. 注:centos7系统在安装完成后,未安装mysql任何版本. 2. rpm -e --nodeps mysql ...

  5. Django-1- urls的路由配置, 命名, 重定向, path及re_path

    1-项目目录下配置(path方法) 这里的访问路径可以是127.0.0.1:8000/index/      2-APP目录下配置(path方法) 这里的访问路径可以是127.0.0.1:8000/t ...

  6. vue typescript ui库

    https://blog.csdn.net/phj_88/article/details/81302043 vuetifyjs

  7. 【spring源码分析】IOC容器初始化(八)

    前言:在上文bean加载过程中还要一个非常重要的方法没有分析createBean,该方法非常重要,因此特意提出来单独分析. createBean方法定义在AbstractBeanFactory中: 该 ...

  8. python从开始到放弃想标题的day12

    上次有说道函数的返回值,但是不是所有的数据类型都有返回值,一些常用的比如str基本都有返回值,list基本都没有返回值,dict基本都有返回值,还有就是函数和函数之间的数据是互不影响的,哪怕是一个函数 ...

  9. A Diversity-Promoting Objective Function for Neural Conversation Models论文阅读

    本文来自李纪为博士的论文 A Diversity-Promoting Objective Function for Neural Conversation Models 1,概述 对于seq2seq模 ...

  10. 作业2:分布式版本控制系统Git的安装与使用

    1.下载安装配置用户名和邮箱. 2. 创建工作目录并通过git init命令把这个目录变成Git可以管理的仓库. 3. 在工作目录下准备文本文件,建议下载Notepad++代替记事本. 4. 组合用g ...