Skip to content

Commit 91c8a73

Browse files
committed
Add RemoveStars and ComplexNumberMultiply string algorithms
1 parent dfa6bf0 commit 91c8a73

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.thealgorithms.strings;
2+
3+
/**
4+
* Removes characters affected by '*' in a string.
5+
* Each '*' deletes the closest non-star character to its left.
6+
*
7+
* Example:
8+
* Input: leet**cod*e
9+
* Output: lecoe
10+
*/
11+
12+
public final class RemoveStars {
13+
14+
private RemoveStars() {
15+
// Private constructor to prevent instantiation(object creation)
16+
}
17+
18+
public static String removeStars(String s) {
19+
StringBuilder result = new StringBuilder();
20+
21+
for (char c : s.toCharArray()) {
22+
if (c == '*') {
23+
if (result.length() > 0) {
24+
result.deleteCharAt(result.length() - 1);
25+
}
26+
} else {
27+
result.append(c);
28+
}
29+
}
30+
return result.toString();
31+
}
32+
public static void main(String[] args) {
33+
String example = "leet**cod*e";
34+
System.out.println(removeStars(example));
35+
}
36+
}

0 commit comments

Comments
 (0)