| | | 1 | | // -------------------------------------------------------------------------------- |
| | | 2 | | // Copyright (C) 2026 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 | | namespace LeetCode.Algorithms.TrimTrailingVowels; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Time complexity - O(n) |
| | | 16 | | /// Space complexity - O(1) |
| | | 17 | | /// </summary> |
| | | 18 | | public sealed class TrimTrailingVowelsIterative : ITrimTrailingVowels |
| | | 19 | | { |
| | | 20 | | public string TrimTrailingVowels(string s) |
| | 3 | 21 | | { |
| | 3 | 22 | | var length = s.Length; |
| | | 23 | | |
| | 10 | 24 | | while (length > 0 && IsVowel(s[length - 1])) |
| | 7 | 25 | | { |
| | 7 | 26 | | length--; |
| | 7 | 27 | | } |
| | | 28 | | |
| | 3 | 29 | | return length == s.Length ? s : s[..length]; |
| | 3 | 30 | | } |
| | | 31 | | |
| | | 32 | | private static bool IsVowel(char c) |
| | 9 | 33 | | { |
| | 9 | 34 | | return c is 'a' or 'e' or 'i' or 'o' or 'u'; |
| | 9 | 35 | | } |
| | | 36 | | } |