Skip to content

Commit bbcc01c

Browse files
solves #2810: Faulty Keyboard in java
1 parent 0b5a511 commit bbcc01c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Diff for: README.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -843,4 +843,4 @@
843843
| 2788 | [Split Strings by Separator](https://leetcode.com/problems/split-strings-by-separator) | [![Java](assets/java.png)](src/SplitStringsBySeparator.java) | |
844844
| 2798 | [Number of Employees Who Met the Target](https://leetcode.com/problems/number-of-employees-who-met-the-target) | [![Java](assets/java.png)](src/NumberOfEmployeesWhoMetTheTarget.java) | |
845845
| 2806 | [Account Balance After Rounded Purchase](https://leetcode.com/problems/account-balance-after-rounded-purchase) | [![Java](assets/java.png)](src/AccountBalanceAfterRoundedPurchase.java) | |
846-
| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | | |
846+
| 2810 | [Faulty Keyboard](https://leetcode.com/problems/faulty-keyboard) | [![Java](assets/java.png)](src/FaultyKeyboard.java) | |

Diff for: src/FaultyKeyboard.java

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// https://leetcode.com/problems/faulty-keyboard
2+
// T: O(N^2)
3+
// S: O(N)
4+
5+
public class FaultyKeyboard {
6+
public String finalString(String s) {
7+
final StringBuilder stringBuilder = new StringBuilder();
8+
for (int i = 0 ; i < s.length() ; i++) {
9+
char character = s.charAt(i);
10+
if (character == 'i') {
11+
stringBuilder.reverse();
12+
} else {
13+
stringBuilder.append(character);
14+
}
15+
}
16+
return stringBuilder.toString();
17+
}
18+
}

0 commit comments

Comments
 (0)