当前位置:网站首页>【1108. IP 地址无效化】
【1108. IP 地址无效化】
2022-06-21 16:00:00 【Sugar_wolf】
来源:力扣(LeetCode)
描述:
给你一个有效的 IPv4 地址 address,返回这个 IP 地址的无效化版本。
所谓无效化 IP 地址,其实就是用 "[.]" 代替了每个 "."。
示例 1:
输入:address = "1.1.1.1"
输出:"1[.]1[.]1[.]1"
示例 2:
输入:address = "255.100.50.0"
输出:"255[.]100[.]50[.]0"
提示:
- 给出的
address是一个有效的 IPv4 地址
思路与算法
按照题目要求,依次将字符串 address 中 ‘.’ 替换为 "[.]" 即可。
代码:
class Solution {
public:
string defangIPaddr(string address) {
string str;
for (auto & c : address) {
if (c == '.') {
str.append("[.]");
}
else {
str.push_back(c);
}
}
return str;
}
};
行用时:0 ms, 在所有 C++ 提交中击败了100.00%的用户
内存消耗:5.8 MB,在所有 C++ 提交中击败了63.65%的用户
复杂度分析
时间复杂度: O(n),其中 n 为字符串 s 的长度。需要遍历一遍字符串即可。
空间复杂度: O(1)。除返回值外,不需要额外的存储空间。
边栏推荐
- Advanced performance test series 4. premise, tool and process of performance test
- SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP
- 期货农产品开户怎么开?手续费是多少?
- Web网页自动化实战《3.在艺龙网中,根据城市+日期+关键词精准匹配了酒店》下篇
- Schéma de développement du système d'échange décentralisé uniswap
- The release of autok3s v0.5.0 continues to be simple and friendly
- Wise people: three no's, four no's and five no's, the ancient way of dealing with people
- WDS must know and know
- 深入理解零拷贝技术
- Google Earth engine (GEE) - use sentinel-2 data acquisition to obtain the NDVI difference of one month ago (Guatemala as an example)
猜你喜欢

微信小程序开发入门介绍-布局组件

Standing at the digital tuyere, how can tooling enterprises' fly up '

Implementation and landing of any to any real-time voice change RTC dev Meetup

IDC咨询:2022年中国关系型数据库软件市场,变革即将到来

IDC Consulting: in 2022, China's relational database software market is about to change

Web3 security series 𞓜 attack types and lessons learned

Remote connection raspberry pie in VNC Viewer Mode

Any to Any 实时变声的实现与落地丨RTC Dev Meetup

Huawei cloud releases desktop ide codearts

Esp8266 / esp32 obtenir la méthode NTP time via la Bibliothèque timelib
随机推荐
Web3 security series 𞓜 attack types and lessons learned
Esp8266/esp32 get NTP time method through timelib Library
我给航母做3D还原:这三处细节,太震撼了…
关于cookie和session的一些理解
未定义的函数或变量【一文讲透】(Matlab)
[live broadcast preview] at 19:00 on June 24, hcsd live broadcast -- employment guide, which will take you through the interview points for the upcoming autumn recruitment and summer internship~~
海瑞科技完成数千万元Pre-A轮融资,打造国内首个人工智能配电物联网
依靠可信AI的鲁棒性有效识别深度伪造,帮助银行对抗身份欺诈
Standing at the digital tuyere, how can tooling enterprises "fly"
Advanced performance test series 2. software performance test, load test and stress test
2022年Q1手机银行用户规模达6.5亿,加强ESG个人金融产品创新
2022年Q1手机银行用户规模达6.5亿,加强ESG个人金融产品创新
关于规范共有产权住房出租管理工作的通知(试行)
Web网页自动化实战《2.在艺龙网中,根据城市+日期+关键词精准匹配了酒店》上篇
mysql提升效率
强化学习入门项目spinning up(1)安装
【数学建模】MATLAB应用实战系列(九十五)-时间序列预测应用案例(附MATLAB代码)
谷歌 Chrome 浏览器全新下载窗口将支持文件拖拽,Edge 已经支持
微信小程序-TabBar用法
Web网页自动化实战《4.获取所有酒店的名字、价格、评分信息,并写入文件》上篇