Skip to content

Commit 53dfb60

Browse files
committed
feat: add solutions to lc problem: No.1108. Defanging an IP Address
1 parent 04254a3 commit 53dfb60

File tree

6 files changed

+80
-3
lines changed

6 files changed

+80
-3
lines changed

solution/1100-1199/1108.Defanging an IP Address/README.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,45 @@
4444
<!-- 这里可写当前语言的特殊实现逻辑 -->
4545

4646
```python
47-
47+
class Solution:
48+
def defangIPaddr(self, address: str) -> str:
49+
return address.replace('.', '[.]')
4850
```
4951

5052
### **Java**
5153

5254
<!-- 这里可写当前语言的特殊实现逻辑 -->
5355

5456
```java
57+
class Solution {
58+
public String defangIPaddr(String address) {
59+
return address.replace(".", "[.]");
60+
}
61+
}
62+
```
63+
64+
### **C++**
65+
66+
```cpp
67+
class Solution {
68+
public:
69+
string defangIPaddr(string address) {
70+
for (int i = address.size(); i >= 0; --i){
71+
if (address[i] == '.') {
72+
address.replace(i, 1, "[.]");
73+
}
74+
}
75+
return address;
76+
}
77+
};
78+
```
79+
80+
### **Go**
5581
82+
```go
83+
func defangIPaddr(address string) string {
84+
return strings.Replace(address, ".", "[.]", -1)
85+
}
5686
```
5787

5888
### **...**

solution/1100-1199/1108.Defanging an IP Address/README_EN.md

+31-1
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,43 @@
4545
### **Python3**
4646

4747
```python
48-
48+
class Solution:
49+
def defangIPaddr(self, address: str) -> str:
50+
return address.replace('.', '[.]')
4951
```
5052

5153
### **Java**
5254

5355
```java
56+
class Solution {
57+
public String defangIPaddr(String address) {
58+
return address.replace(".", "[.]");
59+
}
60+
}
61+
```
62+
63+
### **C++**
64+
65+
```cpp
66+
class Solution {
67+
public:
68+
string defangIPaddr(string address) {
69+
for (int i = address.size(); i >= 0; --i){
70+
if (address[i] == '.') {
71+
address.replace(i, 1, "[.]");
72+
}
73+
}
74+
return address;
75+
}
76+
};
77+
```
78+
79+
### **Go**
5480
81+
```go
82+
func defangIPaddr(address string) string {
83+
return strings.Replace(address, ".", "[.]", -1)
84+
}
5585
```
5686

5787
### **...**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
public:
3+
string defangIPaddr(string address) {
4+
for (int i = address.size(); i >= 0; --i){
5+
if (address[i] == '.') {
6+
address.replace(i, 1, "[.]");
7+
}
8+
}
9+
return address;
10+
}
11+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
func defangIPaddr(address string) string {
2+
return strings.Replace(address, ".", "[.]", -1)
3+
}

solution/1100-1199/1108.Defanging an IP Address/Solution.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ class Solution {
22
public String defangIPaddr(String address) {
33
return address.replace(".", "[.]");
44
}
5-
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def defangIPaddr(self, address: str) -> str:
3+
return address.replace('.', '[.]')

0 commit comments

Comments
 (0)