Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ca3d141

Browse files
committed
Have implemented the program to find the Goal parse interpretation.
1 parent 10d9d27 commit ca3d141

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

.idea/workspace.xml

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Goal Parser Interpretation
3+
Link: https://leetcode.com/problems/goal-parser-interpretation/
4+
5+
You own a Goal Parser that can interpret a string command. The command consists of an alphabet of "G", "()" and/or "(al)" in some order. The Goal Parser will interpret "G" as the string "G", "()" as the string "o", and "(al)" as the string "al". The interpreted strings are then concatenated in the original order.
6+
7+
Given the string command, return the Goal Parser's interpretation of command.
8+
9+
Example 1:
10+
Input: command = "G()(al)"
11+
Output: "Goal"
12+
Explanation: The Goal Parser interprets the command as follows:
13+
G -> G
14+
() -> o
15+
(al) -> al
16+
The final concatenated result is "Goal".
17+
18+
Example 2:
19+
Input: command = "G()()()()(al)"
20+
Output: "Gooooal"
21+
22+
Example 3:
23+
Input: command = "(al)G(al)()()G"
24+
Output: "alGalooG"
25+
26+
Constraints:
27+
1 <= command.length <= 100
28+
command consists of "G", "()", and/or "(al)" in some order.
29+
*/
30+
31+
package com.raj;
32+
33+
public class GoalParserInterpretation {
34+
public static void main(String[] args) {
35+
// Initialization.
36+
String command = "G()(al)";
37+
StringBuilder ans = new StringBuilder();
38+
39+
// Logic.
40+
for (int i = 0; i < command.length(); i++) {
41+
if (command.charAt(i) == '(') {
42+
if (command.charAt(i + 1) == ')') {
43+
ans.append("o");
44+
i += 1;
45+
} else {
46+
ans.append("al");
47+
i += 3;
48+
}
49+
} else {
50+
ans.append("G");
51+
}
52+
}
53+
54+
// Display the result.
55+
System.out.println("The final parse interpretation is: " + ans.toString());
56+
}
57+
}

0 commit comments

Comments
 (0)