953. Verifying an Alien Dictionary Easy
1/**
2 * [953] Verifying an Alien Dictionary
3 *
4 * In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.
5 * Given a sequence of words written in the alien language, and the order of the alphabet, return true if and only if the given words are sorted lexicographically in this alien language.
6 *
7 * Example 1:
8 *
9 * Input: words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"
10 * Output: true
11 * Explanation: As 'h' comes before 'l' in this language, then the sequence is sorted.
12 *
13 * Example 2:
14 *
15 * Input: words = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz"
16 * Output: false
17 * Explanation: As 'd' comes after 'l' in this language, then words[0] > words[1], hence the sequence is unsorted.
18 *
19 * Example 3:
20 *
21 * Input: words = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz"
22 * Output: false
23 * Explanation: The first three characters "app" match, and the second string is shorter (in size.) According to lexicographical rules "apple" > "app", because 'l' > '∅', where '∅' is defined as the blank character which is less than any other character (<a href="https://en.wikipedia.org/wiki/Lexicographical_order" target="_blank">More info</a>).
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= words.length <= 100
29 * 1 <= words[i].length <= 20
30 * order.length == 26
31 * All characters in words[i] and order are English lowercase letters.
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/verifying-an-alien-dictionary/
37// discuss: https://leetcode.com/problems/verifying-an-alien-dictionary/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn is_alien_sorted(words: Vec<String>, order: String) -> bool {
43 false
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_953() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.