| | 1 | | // -------------------------------------------------------------------------------- |
| | 2 | | // Copyright (C) 2025 Eugene Eremeev (also known as Yevhenii Yeriemeieiv). |
| | 3 | | // All Rights Reserved. |
| | 4 | | // -------------------------------------------------------------------------------- |
| | 5 | | // This software is the confidential and proprietary information of Eugene Eremeev |
| | 6 | | // (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not |
| | 7 | | // disclose such Confidential Information and shall use it only in accordance with |
| | 8 | | // the terms of the license agreement you entered into with Eugene Eremeev (also |
| | 9 | | // known as Yevhenii Yeriemeieiv). |
| | 10 | | // -------------------------------------------------------------------------------- |
| | 11 | |
|
| | 12 | | using System.Text; |
| | 13 | |
|
| | 14 | | namespace LeetCode.Algorithms.GoalParserInterpretation; |
| | 15 | |
|
| | 16 | | /// <inheritdoc /> |
| | 17 | | public class GoalParserInterpretationStringBuilder : IGoalParserInterpretation |
| | 18 | | { |
| | 19 | | /// <summary> |
| | 20 | | /// Time complexity - O(n) |
| | 21 | | /// Space complexity - O(n) |
| | 22 | | /// </summary> |
| | 23 | | /// <param name="command"></param> |
| | 24 | | /// <returns></returns> |
| | 25 | | public string Interpret(string command) |
| 3 | 26 | | { |
| 3 | 27 | | var stringBuilder = new StringBuilder(); |
| | 28 | |
|
| 36 | 29 | | for (var i = 0; i < command.Length; i++) |
| 15 | 30 | | { |
| 15 | 31 | | if (i < command.Length - 1) |
| 14 | 32 | | { |
| 14 | 33 | | switch (command[i]) |
| | 34 | | { |
| 11 | 35 | | case '(' when command[i + 1] == ')': |
| 7 | 36 | | stringBuilder.Append('o'); |
| 7 | 37 | | i++; |
| 7 | 38 | | break; |
| | 39 | | case '(': |
| 4 | 40 | | stringBuilder.Append("al"); |
| 4 | 41 | | i += 3; |
| 4 | 42 | | break; |
| | 43 | | default: |
| 3 | 44 | | stringBuilder.Append(command[i]); |
| 3 | 45 | | break; |
| | 46 | | } |
| 14 | 47 | | } |
| | 48 | | else |
| 1 | 49 | | { |
| 1 | 50 | | stringBuilder.Append(command[i]); |
| 1 | 51 | | } |
| 15 | 52 | | } |
| | 53 | |
|
| 3 | 54 | | return stringBuilder.ToString(); |
| 3 | 55 | | } |
| | 56 | | } |