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. informix存储过程笔记

    一.存储过程概述 存储过程是一个用户定义的函数,由存储过程语句(SPL) 和一组SQL语句组成,以可以执行代码形式存储在数据库中,和表.视图.索引等一样,是数据库的一种对象. 存储过程语言SPL(St ...

  2. Android launcher 壁纸 wallpaper

    壁纸分为动态和静态两种: 如果只需要修改默认静态壁纸,替换frameworks/base/core/res/res/drawable/default_wallpaper.jpg即可,或者在源码中修改对 ...

  3. 数据结构:关键路径,利用DFS遍历每一条关键路径JAVA语言实现

    这是我们学校做的数据结构课设,要求分别输出关键路径,我查遍资料java版的只能找到关键路径,但是无法分别输出关键路径 c++有可以分别输出的,所以在明白思想后自己写了一个java版的 函数带有输入函数 ...

  4. Maven入门教程(一)

    1.Maven的简介 1.1 什么是maven 是apache下的一个开源项目,是纯java开发,并且只是用来管理java项目的.Maven是一个项目管理工具,它包含了一个项目对象模型 (Projec ...

  5. Window10上安装Redis及其客户端

    资源下载地址 Redis安装包:https://github.com/MicrosoftArchive/redis/releases Redis客户端: 链接:https://pan.baidu.co ...

  6. Jenkins 使用Tfs 插件出现 MappingConflictException 错误问题解决

    FATAL: com.microsoft.tfs.core.clients.versioncontrol.exceptions.MappingConflictException: The path C ...

  7. kubeadm快速搭建k8s集群

    环境 master01:192.168.1.110 (最少2核CPU) node01:192.168.1.100 规划 services网络:10.96.0.0/12 pod网络:10.244.0.0 ...

  8. CentOS 7 系统下 GitLab 搭建

    参考地址:https://blog.csdn.net/t748588330/article/details/79915003 1. 安装:使用 GitLab 提供仓库在线安装 curl -sS htt ...

  9. angularjs html 转义

    angularjs html 转义 默认情况下,AngularJS对会对插值指令求职表达式(模型)中的任何HTML标记都进行转义,例如以下模型: $scope.msg = “hello,<b&g ...

  10. 分布式存储ceph——(3)ceph常用命令

    1.查看ceph集群配置信息 1 ceph daemon /var/run/ceph/ceph-mon.$(hostname -s).asok config show   2.在部署节点修改了ceph ...