Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 77df86c

Browse files
committed
Added Useful Links
1 parent a3ecac0 commit 77df86c

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.string;
2+
3+
/**
4+
* Given a valid (IPv4) IP address, return a defanged version of that IP address.
5+
*
6+
* A defanged IP address replaces every period "." with "[.]".
7+
*
8+
* Example 1:
9+
*
10+
* Input: address = "1.1.1.1"
11+
* Output: "1[.]1[.]1[.]1"
12+
* Example 2:
13+
*
14+
* Input: address = "255.100.50.0"
15+
* Output: "255[.]100[.]50[.]0"
16+
*/
17+
public class DefangingAnIpAddress {
18+
19+
public static void main (String args[]){
20+
String s = defangIPaddr("198.100.100.100");
21+
System.out.println(s);
22+
}
23+
24+
public static String defangIPaddr(String address) {
25+
StringBuilder sb = new StringBuilder();
26+
for (char c : address.toCharArray()) {
27+
if (c == '.') {
28+
sb.append("[.]");
29+
}
30+
else {
31+
sb.append(c);
32+
}
33+
}
34+
35+
return sb.toString();
36+
}
37+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.string;
2+
3+
import java.util.Arrays;
4+
import java.util.HashSet;
5+
import java.util.Set;
6+
7+
public class RemoveVowelsFromString {
8+
9+
public static void main(String args[]) {
10+
String input = "hello";
11+
StringBuilder output = removeVowels(input);
12+
System.out.println(output);
13+
}
14+
15+
private static StringBuilder removeVowels(String input) {
16+
Set<Character> vowelSet = new HashSet<>(Arrays.asList('a', 'e', 'i', 'o', 'u'));
17+
StringBuilder output = new StringBuilder();
18+
for (Character c : input.toCharArray()) {
19+
if (!vowelSet.contains(c)) {
20+
output.append(c);
21+
}
22+
}
23+
return output;
24+
25+
}
26+
}

src/main/java/com/theory/UsefulLinks

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://cheatsheet.dennyzhang.com/cheatsheet-leetcode-A4

0 commit comments

Comments
 (0)