Skip to content

Commit c2a941d

Browse files
committed
feat: add more
1 parent 27ae84e commit c2a941d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// https://leetcode.com/problems/goal-parser-interpretation
2+
//
3+
// 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.
4+
//
5+
// Given the string `command`, return _the **Goal Parser**'s interpretation of_ `command`.
6+
//
7+
// **Example 1:**
8+
//
9+
// ```
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+
//
19+
// **Example 2:**
20+
//
21+
// ```
22+
// **Input:** command = "G()()()()(al)"
23+
// **Output:** "Gooooal"
24+
// ```
25+
//
26+
// **Example 3:**
27+
//
28+
// ```
29+
// **Input:** command = "(al)G(al)()()G"
30+
// **Output:** "alGalooG"
31+
// ```
32+
//
33+
// **Constraints:**
34+
//
35+
// * `1 <= command.length <= 100`
36+
// * `command` consists of `"G"`, `"()"`, and/or `"(al)"` in some order.
37+
38+
pub fn interpret(command: String) -> String {
39+
return str::replace(&str::replace(&command, "()", "o"), "(al)", "al").to_string()
40+
}
41+
42+
#[test]
43+
pub fn t1() {
44+
assert_eq!(interpret("G()(al)".to_string()), "Goal");
45+
}

String/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ mod _1119_remove_vowels_from_a_string;
55
mod _1859_sorting_the_sentence;
66
mod _2042_check_if_numbers_are_ascending_in_a_sentence;
77
mod _2325_decode_the_message;
8+
mod _1678_goal_parser_interpretation;

0 commit comments

Comments
 (0)