Skip to content

Commit 08fbe8b

Browse files
committed
Add Defanging An IP Address
1 parent 26b672e commit 08fbe8b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//Problem:https://leetcode.com/problems/defanging-an-ip-address/
2+
using System.Text;
3+
4+
namespace LeetCode {
5+
public partial class Solution {
6+
//Runtime:84ms Memorry:23.2MB
7+
public string DefangIPaddr(string address) {
8+
var builder = new StringBuilder();
9+
foreach(var character in address) {
10+
if(character == '.') {
11+
builder.Append("[.]");
12+
}
13+
else {
14+
builder.Append(character);
15+
}
16+
}
17+
18+
return builder.ToString();
19+
}
20+
21+
//Runtime: 72ms Memory:23.6MB
22+
public string DefangIPaddrWithReplace(string address) {
23+
return address.Replace(".", "[.]");
24+
}
25+
}
26+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ LeetCode C# solutions
77
|**509**| **[Fibonacci Number](https://leetcode.com/problems/fibonacci-number/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/509-FibonacciNumber.cs)** | **Easy** |
88
|**682**| **[Baseball Game](https://leetcode.com/problems/baseball-game/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/682-BaseballGame.cs)** | **Easy** |
99
|**933**| **[Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/933-NumberofRecentCalls.cs)** | **Easy** |
10+
|**1108**| **[Defanging an IP Address](https://leetcode.com/problems/defanging-an-ip-address/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/1108-DefangingAnIPAddress.cs)** | **Easy** |
1011
|**1431**| **[Kids With the Greatest Number of Candies](https://leetcode.com/problems/kids-with-the-greatest-number-of-candies/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/1431-KidsWithGreatestNumberofCandies.cs)** | **Easy** |
1112
|**1556**| **[Thousand Separator](https://leetcode.com/problems/thousand-separator/)** | **[C#](https://github.com/ocimen/leetcode/blob/main/LeetCode/1556-ThousandSeparator.cs)** | **Easy** |

0 commit comments

Comments
 (0)