Skip to content

Latest commit

 

History

History
30 lines (26 loc) · 807 Bytes

Question_1678.md

File metadata and controls

30 lines (26 loc) · 807 Bytes

LeetCode Records - Question 1678 Goal Parser Interpretation

Attempt 1: Check the first character

class Solution {
    public String interpret(String command) {
        char[] arr = command.toCharArray();
        StringBuilder stringBuilder = new StringBuilder();

        for (int i = 0; i < arr.length;) {
            if (arr[i] == 'G') {
                stringBuilder.append('G');
                i++;
            } else if (arr[i] == '(' && arr[i + 1] == ')') {
                stringBuilder.append('o');
                i += 2;
            } else {
                stringBuilder.append("al");
                i += 4;
            }
        }

        return stringBuilder.toString();
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 41.40 MB (Beats: 50.03%)