Skip to content

Commit a230327

Browse files
Merge pull request #1874 from CodingTestStudy2/염혜정
[염혜정] Day22
2 parents 7a44695 + 0a05db9 commit a230327

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// O(n)
2+
3+
class Solution {
4+
public String rearrangeString(String s, char x, char y) {
5+
StringBuilder left = new StringBuilder();
6+
StringBuilder mid = new StringBuilder();
7+
StringBuilder right = new StringBuilder();
8+
9+
for (char c : s.toCharArray()) {
10+
if (c == y) left.append(c);
11+
else if (c == x) right.append(c);
12+
else mid.append(c);
13+
}
14+
return left.toString() + mid.toString() + right.toString();
15+
}
16+
}

0 commit comments

Comments
 (0)