1859. Sorting the Sentence Easy
1/**
2 * [1859] Sorting the Sentence
3 *
4 * A sentence is a list of words that are separated by a single space with no leading or trailing spaces. Each word consists of lowercase and uppercase English letters.
5 *
6 * A sentence can be shuffled by appending the 1-indexed word position to each word then rearranging the words in the sentence.
7 *
8 *
9 * For example, the sentence "This is a sentence" can be shuffled as "sentence4 a3 is2 This1" or "is2 sentence4 This1 a3".
10 *
11 *
12 * Given a shuffled sentence s containing no more than 9 words, reconstruct and return the original sentence.
13 *
14 *
15 * Example 1:
16 *
17 *
18 * Input: s = "is2 sentence4 This1 a3"
19 * Output: "This is a sentence"
20 * Explanation: Sort the words in s to their original positions "This1 is2 a3 sentence4", then remove the numbers.
21 *
22 *
23 * Example 2:
24 *
25 *
26 * Input: s = "Myself2 Me1 I4 and3"
27 * Output: "Me Myself and I"
28 * Explanation: Sort the words in s to their original positions "Me1 Myself2 and3 I4", then remove the numbers.
29 *
30 *
31 *
32 * Constraints:
33 *
34 *
35 * 2 <= s.length <= 200
36 * s consists of lowercase and uppercase English letters, spaces, and digits from 1 to 9.
37 * The number of words in s is between 1 and 9.
38 * The words in s are separated by a single space.
39 * s contains no leading or trailing spaces.
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/sorting-the-sentence/
45// discuss: https://leetcode.com/problems/sorting-the-sentence/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn sort_sentence(s: String) -> String {
51 String::new()
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_1859() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.