| | 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.GenerateTagForVideoCaption; |
| | 15 | |
|
| | 16 | | /// <inheritdoc /> |
| | 17 | | public class GenerateTagForVideoCaptionStringBuilder : IGenerateTagForVideoCaption |
| | 18 | | { |
| | 19 | | /// <summary> |
| | 20 | | /// Time complexity - O(n) |
| | 21 | | /// Space complexity - O(n) |
| | 22 | | /// </summary> |
| | 23 | | /// <param name="caption"></param> |
| | 24 | | /// <returns></returns> |
| | 25 | | public string GenerateTag(string caption) |
| 3 | 26 | | { |
| 3 | 27 | | if (string.IsNullOrWhiteSpace(caption)) |
| 0 | 28 | | { |
| 0 | 29 | | return "#"; |
| | 30 | | } |
| | 31 | |
|
| 3 | 32 | | var words = caption.Split(' ', StringSplitOptions.RemoveEmptyEntries); |
| | 33 | |
|
| 3 | 34 | | var tagStringBuilder = new StringBuilder(100, 100); |
| | 35 | |
|
| 3 | 36 | | tagStringBuilder.Append('#'); |
| | 37 | |
|
| 3 | 38 | | var firstWord = words[0].ToLowerInvariant(); |
| | 39 | |
|
| 230 | 40 | | foreach (var c in firstWord) |
| 111 | 41 | | { |
| 111 | 42 | | if (tagStringBuilder.Length == 100) |
| 1 | 43 | | { |
| 1 | 44 | | return tagStringBuilder.ToString(); |
| | 45 | | } |
| | 46 | |
|
| 110 | 47 | | tagStringBuilder.Append(c); |
| 110 | 48 | | } |
| | 49 | |
|
| 16 | 50 | | for (var i = 1; i < words.Length; i++) |
| 6 | 51 | | { |
| 6 | 52 | | if (tagStringBuilder.Length == 100) |
| 0 | 53 | | { |
| 0 | 54 | | break; |
| | 55 | | } |
| | 56 | |
|
| 6 | 57 | | tagStringBuilder.Append(char.ToUpperInvariant(words[i][0])); |
| | 58 | |
|
| 54 | 59 | | for (var j = 1; j < words[i].Length; j++) |
| 21 | 60 | | { |
| 21 | 61 | | if (tagStringBuilder.Length == 100) |
| 0 | 62 | | { |
| 0 | 63 | | break; |
| | 64 | | } |
| | 65 | |
|
| 21 | 66 | | tagStringBuilder.Append(char.ToLowerInvariant(words[i][j])); |
| 21 | 67 | | } |
| 6 | 68 | | } |
| | 69 | |
|
| 2 | 70 | | return tagStringBuilder.ToString(); |
| 3 | 71 | | } |
| | 72 | | } |