Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 587 Bytes

Question_2810.md

File metadata and controls

24 lines (20 loc) · 587 Bytes

LeetCode Records - Question 2810 Faulty Keyboard

Attempt 1: Use reverse() and toCharArray()

class Solution {
    public String finalString(String s) {
        StringBuilder stringBuilder = new StringBuilder();

        for (char ch : s.toCharArray()) {
            if (ch == 'i') {
                stringBuilder = stringBuilder.reverse();
            } else {
                stringBuilder.append(ch);
            }
        }

        return stringBuilder.toString();
    }
}
  • Runtime: 3 ms (Beats: 98.78%)
  • Memory: 44.52 MB (Beats: 71.15%)