当前位置:网站首页>力扣 1108. IP 地址无效化
力扣 1108. IP 地址无效化
2022-06-22 10:04:00 【冷酷的摸鱼小将】
题目
给你一个有效的 IPv4 地址 address,返回这个 IP 地址的无效化版本。
所谓无效化 IP 地址,其实就是用 “[.]” 代替了每个 “.”。
示例
输入:address = “1.1.1.1”
输出:“1[.]1[.]1[.]1”
输入:address = “255.100.50.0”
输出:“255[.]100[.]50[.]0”
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/defanging-an-ip-address
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
方法1:模拟
Java实现
class Solution {
public String defangIPaddr(String address) {
StringBuffer res = new StringBuffer();
int n = address.length();
for (int i = 0; i < n; i++) {
char c = address.charAt(i);
if (c != '.') {
res.append(c);
} else {
res.append("[.]");
}
}
return res.toString();
}
}

边栏推荐
- Bloom filter optimization - crimsondb series of papers (I)
- The solution for golang Mongo go driver find() to read 101 records by default
- [structure training camp - module 3]
- Who says PostgreSQL has no reliable high availability (2)
- thinkphp3.2.3日志包含分析
- 6-43 sum of ordered sparse polynomials
- [popular science] to understand supervised learning, unsupervised learning and reinforcement learning
- PAT甲级 - 1013 Battle Over Cities(删点判连通块数量)
- What kind of experience is middle-aged unemployment
- Summary and Prospect of AI security technology | community essay solicitation
猜你喜欢

APM 飞行模式切换--源码详解

MySQL中from_unixtime和unix_timestamp处理数据库时间戳转换问题-案例

Attack and defense world web practice area beginner level

xlrd.biffh.XLRDError: Excel xlsx file; not supported 解决办法

Ctfshow web realizes killing through one question

TikTok 宣布将数据存储于 Oracle 服务器!

TCP建立连接过程(深入源码理解3次握手)

Target detection / segmentation training using pytorch mask RCNN

Pytorch实现波阻抗反演

Tiktok announces data storage on Oracle server!
随机推荐
Cobalt strike from entry to imprisonment (III)
秋招秘籍B
Read the history of it development in one breath
一口气读懂 IT发展史
Attack and defense world web practice area beginner level
秋招秘籍A
搭建OpenPGP Key server
What kind of experience is middle-aged unemployment
[Luogu] P1083 [NOIP2012 提高组] 借教室(差分)
6-8 integer array shift
信号完整性(SI)电源完整性(PI)学习笔记(二十四)差分对与差分阻抗(四)
php 数据库 mysql提问
PAT甲级 1016 Phone Bills(时间差)
day575: 分糖果
Ctfshow Web Learning Records
The solution for golang Mongo go driver find() to read 101 records by default
PowerDesigner技巧2 触发器模板
Encryption market plummeted, Seth triggered a new round of concern
MySQL中from_unixtime和unix_timestamp处理数据库时间戳转换问题-案例
前 AMD 芯片架构师吐槽,取消 K12 处理器项目是因为 AMD 怂了!