Files

71 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# [2785] Sort Vowels In A String
## 題目資訊
- **難度**: Medium
- **標籤**: String, Sorting
- **題目連結**: [LeetCode](https://leetcode.com/problems/sort-vowels-in-a-string/)
- **練習日期**: 2025-09-11
## 題目描述
給定一個 0-indexed 的字串 s重新排列 s 以獲得新字串 t使得
所有子音保持在原來的位置
母音必須按照 ASCII 值的非遞減順序排序
更正式地說:
如果存在索引 i其中 0 <= i < s.length s[i] 是子音那麼 t[i] = s[i]
對於索引對 i, j其中 0 <= i < j < s.length s[i] s[j] 都是母音那麼 t[i] ASCII 值不能高於 t[j]
母音定義: 'a', 'e', 'i', 'o', 'u' 以及它們的大寫形式
## 解題思路
### 初步分析
- 這題主要考察什麼概念
這題主要考察字串處理和排序概念
- 有什麼關鍵限制條件
- 預期時間/空間複雜度
O(n log k) / O(k)其中 n 為字串長度k 為母音數量
### 解法概述
1. **解法**:
- 思路
1. 遍歷字串收集所有母音及其位置
2. 對母音字符進行排序
3. 將排序後的母音按原位置重新放回字串
- 時間複雜度O(n + k log k) 其中 n 是字串長度k 是母音數量
- 空間複雜度O(k) 存儲母音字符和位置
## 測試案例
### 範例輸入輸出
```
Input: s = "lEetcOde"
Output: "lEOtcede"
Explanation:
母音 'E', 'e', 'O', 'e' 排序後變成 'E', 'O', 'e', 'e'
```
### 邊界情況
- `1 <= s.length <= 10^5`
- `s` consists only of letters of the English alphabet in uppercase and lowercase.
## 學習筆記
### 今天學到什麼?
-
### 遇到的困難
-
### 改善方向
-
### 相關題目
- [題目編號] 題目名稱 - 相似概念
- [題目編號] 題目名稱 - 進階版本
---
**總結**: 這題的核心概念是...適合練習...技巧