mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
189 lines
34 KiB
JSON
189 lines
34 KiB
JSON
{
|
||
"data": {
|
||
"question": {
|
||
"questionId": "1433",
|
||
"questionFrontendId": "2227",
|
||
"categoryTitle": "Algorithms",
|
||
"boundTopicId": 1385208,
|
||
"title": "Encrypt and Decrypt Strings",
|
||
"titleSlug": "encrypt-and-decrypt-strings",
|
||
"content": "<p>You are given a character array <code>keys</code> containing <strong>unique</strong> characters and a string array <code>values</code> containing strings of length 2. You are also given another string array <code>dictionary</code> that contains all permitted original strings after decryption. You should implement a data structure that can encrypt or decrypt a <strong>0-indexed</strong> string.</p>\n\n<p>A string is <strong>encrypted</strong> with the following process:</p>\n\n<ol>\n\t<li>For each character <code>c</code> in the string, we find the index <code>i</code> satisfying <code>keys[i] == c</code> in <code>keys</code>.</li>\n\t<li>Replace <code>c</code> with <code>values[i]</code> in the string.</li>\n</ol>\n\n<p>Note that in case a character of the string is <strong>not present</strong> in <code>keys</code>, the encryption process cannot be carried out, and an empty string <code>""</code> is returned.</p>\n\n<p>A string is <strong>decrypted</strong> with the following process:</p>\n\n<ol>\n\t<li>For each substring <code>s</code> of length 2 occurring at an even index in the string, we find an <code>i</code> such that <code>values[i] == s</code>. If there are multiple valid <code>i</code>, we choose <strong>any</strong> one of them. This means a string could have multiple possible strings it can decrypt to.</li>\n\t<li>Replace <code>s</code> with <code>keys[i]</code> in the string.</li>\n</ol>\n\n<p>Implement the <code>Encrypter</code> class:</p>\n\n<ul>\n\t<li><code>Encrypter(char[] keys, String[] values, String[] dictionary)</code> Initializes the <code>Encrypter</code> class with <code>keys, values</code>, and <code>dictionary</code>.</li>\n\t<li><code>String encrypt(String word1)</code> Encrypts <code>word1</code> with the encryption process described above and returns the encrypted string.</li>\n\t<li><code>int decrypt(String word2)</code> Returns the number of possible strings <code>word2</code> could decrypt to that also appear in <code>dictionary</code>.</li>\n</ul>\n\n<p> </p>\n<p><strong>Example 1:</strong></p>\n\n<pre>\n<strong>Input</strong>\n["Encrypter", "encrypt", "decrypt"]\n[[['a', 'b', 'c', 'd'], ["ei", "zf", "ei", "am"], ["abcd", "acbd", "adbc", "badc", "dacb", "cadb", "cbda", "abad"]], ["abcd"], ["eizfeiam"]]\n<strong>Output</strong>\n[null, "eizfeiam", 2]\n\n<strong>Explanation</strong>\nEncrypter encrypter = new Encrypter([['a', 'b', 'c', 'd'], ["ei", "zf", "ei", "am"], ["abcd", "acbd", "adbc", "badc", "dacb", "cadb", "cbda", "abad"]);\nencrypter.encrypt("abcd"); // return "eizfeiam". \n // 'a' maps to "ei", 'b' maps to "zf", 'c' maps to "ei", and 'd' maps to "am".\nencrypter.decrypt("eizfeiam"); // return 2. \n // "ei" can map to 'a' or 'c', "zf" maps to 'b', and "am" maps to 'd'. \n // Thus, the possible strings after decryption are "abad", "cbad", "abcd", and "cbcd". \n // 2 of those strings, "abad" and "abcd", appear in dictionary, so the answer is 2.\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= keys.length == values.length <= 26</code></li>\n\t<li><code>values[i].length == 2</code></li>\n\t<li><code>1 <= dictionary.length <= 100</code></li>\n\t<li><code>1 <= dictionary[i].length <= 100</code></li>\n\t<li>All <code>keys[i]</code> and <code>dictionary[i]</code> are <strong>unique</strong>.</li>\n\t<li><code>1 <= word1.length <= 2000</code></li>\n\t<li><code>1 <= word2.length <= 200</code></li>\n\t<li>All <code>word1[i]</code> appear in <code>keys</code>.</li>\n\t<li><code>word2.length</code> is even.</li>\n\t<li><code>keys</code>, <code>values[i]</code>, <code>dictionary[i]</code>, <code>word1</code>, and <code>word2</code> only contain lowercase English letters.</li>\n\t<li>At most <code>200</code> calls will be made to <code>encrypt</code> and <code>decrypt</code> <strong>in total</strong>.</li>\n</ul>\n",
|
||
"translatedTitle": "加密解密字符串",
|
||
"translatedContent": "<p>给你一个字符数组 <code>keys</code> ,由若干 <strong>互不相同</strong> 的字符组成。还有一个字符串数组 <code>values</code> ,内含若干长度为 2 的字符串。另给你一个字符串数组 <code>dictionary</code> ,包含解密后所有允许的原字符串。请你设计并实现一个支持加密及解密下标从 <strong>0</strong> 开始字符串的数据结构。</p>\n\n<p>字符串 <strong>加密</strong> 按下述步骤进行:</p>\n\n<ol>\n\t<li>对字符串中的每个字符 <code>c</code> ,先从 <code>keys</code> 中找出满足 <code>keys[i] == c</code> 的下标 <code>i</code> 。</li>\n\t<li>在字符串中,用 <code>values[i]</code> 替换字符 <code>c</code> 。</li>\n</ol>\n\n<p>字符串 <strong>解密</strong> 按下述步骤进行:</p>\n\n<ol>\n\t<li>将字符串每相邻 2 个字符划分为一个子字符串,对于每个子字符串 <code>s</code> ,找出满足 <code>values[i] == s</code> 的一个下标 <code>i</code> 。如果存在多个有效的 <code>i</code> ,从中选择 <strong>任意</strong> 一个。这意味着一个字符串解密可能得到多个解密字符串。</li>\n\t<li>在字符串中,用 <code>keys[i]</code> 替换 <code>s</code> 。</li>\n</ol>\n\n<p>实现 <code>Encrypter</code> 类:</p>\n\n<ul>\n\t<li><code>Encrypter(char[] keys, String[] values, String[] dictionary)</code> 用 <code>keys</code>、<code>values</code> 和 <code>dictionary</code> 初始化 <code>Encrypter</code> 类。</li>\n\t<li><code>String encrypt(String word1)</code> 按上述加密过程完成对 <code>word1</code> 的加密,并返回加密后的字符串。</li>\n\t<li><code>int decrypt(String word2)</code> 统计并返回可以由 <code>word2</code> 解密得到且出现在 <code>dictionary</code> 中的字符串数目。</li>\n</ul>\n\n<p> </p>\n\n<p><strong>示例:</strong></p>\n\n<pre>\n<strong>输入:</strong>\n[\"Encrypter\", \"encrypt\", \"decrypt\"]\n[[['a', 'b', 'c', 'd'], [\"ei\", \"zf\", \"ei\", \"am\"], [\"abcd\", \"acbd\", \"adbc\", \"badc\", \"dacb\", \"cadb\", \"cbda\", \"abad\"]], [\"abcd\"], [\"eizfeiam\"]]\n<strong>输出:</strong>\n[null, \"eizfeiam\", 2]\n\n<strong>解释:</strong>\nEncrypter encrypter = new Encrypter([['a', 'b', 'c', 'd'], [\"ei\", \"zf\", \"ei\", \"am\"], [\"abcd\", \"acbd\", \"adbc\", \"badc\", \"dacb\", \"cadb\", \"cbda\", \"abad\"]);\nencrypter.encrypt(\"abcd\"); // 返回 \"eizfeiam\"。 \n // 'a' 映射为 \"ei\",'b' 映射为 \"zf\",'c' 映射为 \"ei\",'d' 映射为 \"am\"。\nencrypter.decrypt(\"eizfeiam\"); // return 2. \n // \"ei\" 可以映射为 'a' 或 'c',\"zf\" 映射为 'b',\"am\" 映射为 'd'。 \n // 因此,解密后可以得到的字符串是 \"abad\",\"cbad\",\"abcd\" 和 \"cbcd\"。 \n // 其中 2 个字符串,\"abad\" 和 \"abcd\",在 dictionary 中出现,所以答案是 2 。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>1 <= keys.length == values.length <= 26</code></li>\n\t<li><code>values[i].length == 2</code></li>\n\t<li><code>1 <= dictionary.length <= 100</code></li>\n\t<li><code>1 <= dictionary[i].length <= 100</code></li>\n\t<li>所有 <code>keys[i]</code> 和 <code>dictionary[i]</code> <strong>互不相同</strong></li>\n\t<li><code>1 <= word1.length <= 2000</code></li>\n\t<li><code>1 <= word2.length <= 200</code></li>\n\t<li>所有 <code>word1[i]</code> 都出现在 <code>keys</code> 中</li>\n\t<li><code>word2.length</code> 是偶数</li>\n\t<li><code>keys</code>、<code>values[i]</code>、<code>dictionary[i]</code>、<code>word1</code> 和 <code>word2</code> 只含小写英文字母</li>\n\t<li>至多调用 <code>encrypt</code> 和 <code>decrypt</code> <strong>总计</strong> <code>200</code> 次</li>\n</ul>\n",
|
||
"isPaidOnly": false,
|
||
"difficulty": "Hard",
|
||
"likes": 14,
|
||
"dislikes": 0,
|
||
"isLiked": null,
|
||
"similarQuestions": "[]",
|
||
"contributors": [],
|
||
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"ruby\": false, \"bash\": false, \"swift\": false, \"golang\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"kotlin\": false, \"rust\": false, \"php\": false, \"typescript\": false, \"racket\": false, \"erlang\": false, \"elixir\": false}",
|
||
"topicTags": [
|
||
{
|
||
"name": "Design",
|
||
"slug": "design",
|
||
"translatedName": "设计",
|
||
"__typename": "TopicTagNode"
|
||
},
|
||
{
|
||
"name": "Trie",
|
||
"slug": "trie",
|
||
"translatedName": "字典树",
|
||
"__typename": "TopicTagNode"
|
||
},
|
||
{
|
||
"name": "Array",
|
||
"slug": "array",
|
||
"translatedName": "数组",
|
||
"__typename": "TopicTagNode"
|
||
},
|
||
{
|
||
"name": "Hash Table",
|
||
"slug": "hash-table",
|
||
"translatedName": "哈希表",
|
||
"__typename": "TopicTagNode"
|
||
},
|
||
{
|
||
"name": "String",
|
||
"slug": "string",
|
||
"translatedName": "字符串",
|
||
"__typename": "TopicTagNode"
|
||
}
|
||
],
|
||
"companyTagStats": null,
|
||
"codeSnippets": [
|
||
{
|
||
"lang": "C++",
|
||
"langSlug": "cpp",
|
||
"code": "class Encrypter {\npublic:\n Encrypter(vector<char>& keys, vector<string>& values, vector<string>& dictionary) {\n\n }\n \n string encrypt(string word1) {\n\n }\n \n int decrypt(string word2) {\n\n }\n};\n\n/**\n * Your Encrypter object will be instantiated and called as such:\n * Encrypter* obj = new Encrypter(keys, values, dictionary);\n * string param_1 = obj->encrypt(word1);\n * int param_2 = obj->decrypt(word2);\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Java",
|
||
"langSlug": "java",
|
||
"code": "class Encrypter {\n\n public Encrypter(char[] keys, String[] values, String[] dictionary) {\n\n }\n \n public String encrypt(String word1) {\n\n }\n \n public int decrypt(String word2) {\n\n }\n}\n\n/**\n * Your Encrypter object will be instantiated and called as such:\n * Encrypter obj = new Encrypter(keys, values, dictionary);\n * String param_1 = obj.encrypt(word1);\n * int param_2 = obj.decrypt(word2);\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Python",
|
||
"langSlug": "python",
|
||
"code": "class Encrypter(object):\n\n def __init__(self, keys, values, dictionary):\n \"\"\"\n :type keys: List[str]\n :type values: List[str]\n :type dictionary: List[str]\n \"\"\"\n\n\n def encrypt(self, word1):\n \"\"\"\n :type word1: str\n :rtype: str\n \"\"\"\n\n\n def decrypt(self, word2):\n \"\"\"\n :type word2: str\n :rtype: int\n \"\"\"\n\n\n\n# Your Encrypter object will be instantiated and called as such:\n# obj = Encrypter(keys, values, dictionary)\n# param_1 = obj.encrypt(word1)\n# param_2 = obj.decrypt(word2)",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Python3",
|
||
"langSlug": "python3",
|
||
"code": "class Encrypter:\n\n def __init__(self, keys: List[str], values: List[str], dictionary: List[str]):\n\n\n def encrypt(self, word1: str) -> str:\n\n\n def decrypt(self, word2: str) -> int:\n\n\n\n# Your Encrypter object will be instantiated and called as such:\n# obj = Encrypter(keys, values, dictionary)\n# param_1 = obj.encrypt(word1)\n# param_2 = obj.decrypt(word2)",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "C",
|
||
"langSlug": "c",
|
||
"code": "\n\n\ntypedef struct {\n \n} Encrypter;\n\n\nEncrypter* encrypterCreate(char* keys, int keysSize, char ** values, int valuesSize, char ** dictionary, int dictionarySize) {\n \n}\n\nchar * encrypterEncrypt(Encrypter* obj, char * word1) {\n \n}\n\nint encrypterDecrypt(Encrypter* obj, char * word2) {\n \n}\n\nvoid encrypterFree(Encrypter* obj) {\n \n}\n\n/**\n * Your Encrypter struct will be instantiated and called as such:\n * Encrypter* obj = encrypterCreate(keys, keysSize, values, valuesSize, dictionary, dictionarySize);\n * char * param_1 = encrypterEncrypt(obj, word1);\n \n * int param_2 = encrypterDecrypt(obj, word2);\n \n * encrypterFree(obj);\n*/",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "C#",
|
||
"langSlug": "csharp",
|
||
"code": "public class Encrypter {\n\n public Encrypter(char[] keys, string[] values, string[] dictionary) {\n\n }\n \n public string Encrypt(string word1) {\n\n }\n \n public int Decrypt(string word2) {\n\n }\n}\n\n/**\n * Your Encrypter object will be instantiated and called as such:\n * Encrypter obj = new Encrypter(keys, values, dictionary);\n * string param_1 = obj.Encrypt(word1);\n * int param_2 = obj.Decrypt(word2);\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "JavaScript",
|
||
"langSlug": "javascript",
|
||
"code": "/**\n * @param {character[]} keys\n * @param {string[]} values\n * @param {string[]} dictionary\n */\nvar Encrypter = function(keys, values, dictionary) {\n\n};\n\n/** \n * @param {string} word1\n * @return {string}\n */\nEncrypter.prototype.encrypt = function(word1) {\n\n};\n\n/** \n * @param {string} word2\n * @return {number}\n */\nEncrypter.prototype.decrypt = function(word2) {\n\n};\n\n/**\n * Your Encrypter object will be instantiated and called as such:\n * var obj = new Encrypter(keys, values, dictionary)\n * var param_1 = obj.encrypt(word1)\n * var param_2 = obj.decrypt(word2)\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Ruby",
|
||
"langSlug": "ruby",
|
||
"code": "class Encrypter\n\n=begin\n :type keys: Character[]\n :type values: String[]\n :type dictionary: String[]\n=end\n def initialize(keys, values, dictionary)\n\n end\n\n\n=begin\n :type word1: String\n :rtype: String\n=end\n def encrypt(word1)\n\n end\n\n\n=begin\n :type word2: String\n :rtype: Integer\n=end\n def decrypt(word2)\n\n end\n\n\nend\n\n# Your Encrypter object will be instantiated and called as such:\n# obj = Encrypter.new(keys, values, dictionary)\n# param_1 = obj.encrypt(word1)\n# param_2 = obj.decrypt(word2)",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Swift",
|
||
"langSlug": "swift",
|
||
"code": "\nclass Encrypter {\n\n init(_ keys: [Character], _ values: [String], _ dictionary: [String]) {\n\n }\n \n func encrypt(_ word1: String) -> String {\n\n }\n \n func decrypt(_ word2: String) -> Int {\n\n }\n}\n\n/**\n * Your Encrypter object will be instantiated and called as such:\n * let obj = Encrypter(keys, values, dictionary)\n * let ret_1: String = obj.encrypt(word1)\n * let ret_2: Int = obj.decrypt(word2)\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Go",
|
||
"langSlug": "golang",
|
||
"code": "type Encrypter struct {\n\n}\n\n\nfunc Constructor(keys []byte, values []string, dictionary []string) Encrypter {\n\n}\n\n\nfunc (this *Encrypter) Encrypt(word1 string) string {\n\n}\n\n\nfunc (this *Encrypter) Decrypt(word2 string) int {\n\n}\n\n\n/**\n * Your Encrypter object will be instantiated and called as such:\n * obj := Constructor(keys, values, dictionary);\n * param_1 := obj.Encrypt(word1);\n * param_2 := obj.Decrypt(word2);\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Scala",
|
||
"langSlug": "scala",
|
||
"code": "class Encrypter(_keys: Array[Char], _values: Array[String], _dictionary: Array[String]) {\n\n def encrypt(word1: String): String = {\n\n }\n\n def decrypt(word2: String): Int = {\n\n }\n\n}\n\n/**\n * Your Encrypter object will be instantiated and called as such:\n * var obj = new Encrypter(keys, values, dictionary)\n * var param_1 = obj.encrypt(word1)\n * var param_2 = obj.decrypt(word2)\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Kotlin",
|
||
"langSlug": "kotlin",
|
||
"code": "class Encrypter(keys: CharArray, values: Array<String>, dictionary: Array<String>) {\n\n fun encrypt(word1: String): String {\n\n }\n\n fun decrypt(word2: String): Int {\n\n }\n\n}\n\n/**\n * Your Encrypter object will be instantiated and called as such:\n * var obj = Encrypter(keys, values, dictionary)\n * var param_1 = obj.encrypt(word1)\n * var param_2 = obj.decrypt(word2)\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Rust",
|
||
"langSlug": "rust",
|
||
"code": "struct Encrypter {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl Encrypter {\n\n fn new(keys: Vec<char>, values: Vec<String>, dictionary: Vec<String>) -> Self {\n\n }\n \n fn encrypt(&self, word1: String) -> String {\n\n }\n \n fn decrypt(&self, word2: String) -> i32 {\n\n }\n}\n\n/**\n * Your Encrypter object will be instantiated and called as such:\n * let obj = Encrypter::new(keys, values, dictionary);\n * let ret_1: String = obj.encrypt(word1);\n * let ret_2: i32 = obj.decrypt(word2);\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "PHP",
|
||
"langSlug": "php",
|
||
"code": "class Encrypter {\n /**\n * @param String[] $keys\n * @param String[] $values\n * @param String[] $dictionary\n */\n function __construct($keys, $values, $dictionary) {\n\n }\n\n /**\n * @param String $word1\n * @return String\n */\n function encrypt($word1) {\n\n }\n\n /**\n * @param String $word2\n * @return Integer\n */\n function decrypt($word2) {\n\n }\n}\n\n/**\n * Your Encrypter object will be instantiated and called as such:\n * $obj = Encrypter($keys, $values, $dictionary);\n * $ret_1 = $obj->encrypt($word1);\n * $ret_2 = $obj->decrypt($word2);\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "TypeScript",
|
||
"langSlug": "typescript",
|
||
"code": "class Encrypter {\n constructor(keys: string[], values: string[], dictionary: string[]) {\n\n }\n\n encrypt(word1: string): string {\n\n }\n\n decrypt(word2: string): number {\n\n }\n}\n\n/**\n * Your Encrypter object will be instantiated and called as such:\n * var obj = new Encrypter(keys, values, dictionary)\n * var param_1 = obj.encrypt(word1)\n * var param_2 = obj.decrypt(word2)\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Racket",
|
||
"langSlug": "racket",
|
||
"code": "(define encrypter%\n (class object%\n (super-new)\n \n ; keys : (listof char?)\n ; values : (listof string?)\n ; dictionary : (listof string?)\n (init-field\n keys\n values\n dictionary)\n \n ; encrypt : string? -> string?\n (define/public (encrypt word1)\n\n )\n ; decrypt : string? -> exact-integer?\n (define/public (decrypt word2)\n\n )))\n\n;; Your encrypter% object will be instantiated and called as such:\n;; (define obj (new encrypter% [keys keys] [values values] [dictionary dictionary]))\n;; (define param_1 (send obj encrypt word1))\n;; (define param_2 (send obj decrypt word2))",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Erlang",
|
||
"langSlug": "erlang",
|
||
"code": "-spec encrypter_init_(Keys :: [char()], Values :: [unicode:unicode_binary()], Dictionary :: [unicode:unicode_binary()]) -> any().\nencrypter_init_(Keys, Values, Dictionary) ->\n .\n\n-spec encrypter_encrypt(Word1 :: unicode:unicode_binary()) -> unicode:unicode_binary().\nencrypter_encrypt(Word1) ->\n .\n\n-spec encrypter_decrypt(Word2 :: unicode:unicode_binary()) -> integer().\nencrypter_decrypt(Word2) ->\n .\n\n\n%% Your functions will be called as such:\n%% encrypter_init_(Keys, Values, Dictionary),\n%% Param_1 = encrypter_encrypt(Word1),\n%% Param_2 = encrypter_decrypt(Word2),\n\n%% encrypter_init_ will be called before every test case, in which you can do some necessary initializations.",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Elixir",
|
||
"langSlug": "elixir",
|
||
"code": "defmodule Encrypter do\n @spec init_(keys :: [char], values :: [String.t], dictionary :: [String.t]) :: any\n def init_(keys, values, dictionary) do\n\n end\n\n @spec encrypt(word1 :: String.t) :: String.t\n def encrypt(word1) do\n\n end\n\n @spec decrypt(word2 :: String.t) :: integer\n def decrypt(word2) do\n\n end\nend\n\n# Your functions will be called as such:\n# Encrypter.init_(keys, values, dictionary)\n# param_1 = Encrypter.encrypt(word1)\n# param_2 = Encrypter.decrypt(word2)\n\n# Encrypter.init_ will be called before every test case, in which you can do some necessary initializations.",
|
||
"__typename": "CodeSnippetNode"
|
||
}
|
||
],
|
||
"stats": "{\"totalAccepted\": \"4.4K\", \"totalSubmission\": \"11.4K\", \"totalAcceptedRaw\": 4411, \"totalSubmissionRaw\": 11450, \"acRate\": \"38.5%\"}",
|
||
"hints": [
|
||
"For encryption, use hashmap to map each char of word1 to its value.",
|
||
"For decryption, use trie to prune when necessary."
|
||
],
|
||
"solution": null,
|
||
"status": null,
|
||
"sampleTestCase": "[\"Encrypter\",\"encrypt\",\"decrypt\"]\n[[[\"a\",\"b\",\"c\",\"d\"],[\"ei\",\"zf\",\"ei\",\"am\"],[\"abcd\",\"acbd\",\"adbc\",\"badc\",\"dacb\",\"cadb\",\"cbda\",\"abad\"]],[\"abcd\"],[\"eizfeiam\"]]",
|
||
"metaData": "{\n \"classname\": \"Encrypter\",\n \"constructor\": {\n \"params\": [\n {\n \"name\": \"keys\",\n \"type\": \"character[]\"\n },\n {\n \"type\": \"string[]\",\n \"name\": \"values\"\n },\n {\n \"name\": \"dictionary\",\n \"type\": \"string[]\"\n }\n ]\n },\n \"methods\": [\n {\n \"params\": [\n {\n \"type\": \"string\",\n \"name\": \"word1\"\n }\n ],\n \"name\": \"encrypt\",\n \"return\": {\n \"type\": \"string\"\n }\n },\n {\n \"params\": [\n {\n \"type\": \"string\",\n \"name\": \"word2\"\n }\n ],\n \"name\": \"decrypt\",\n \"return\": {\n \"type\": \"integer\"\n }\n }\n ],\n \"return\": {\n \"type\": \"boolean\"\n },\n \"systemdesign\": true,\n \"manual\": false\n}",
|
||
"judgerAvailable": true,
|
||
"judgeType": "large",
|
||
"mysqlSchemas": [],
|
||
"enableRunCode": true,
|
||
"envInfo": "{\"cpp\":[\"C++\",\"<p>\\u7248\\u672c\\uff1a<code>clang 11<\\/code> \\u91c7\\u7528\\u6700\\u65b0C++ 17\\u6807\\u51c6\\u3002<\\/p>\\r\\n\\r\\n<p>\\u7f16\\u8bd1\\u65f6\\uff0c\\u5c06\\u4f1a\\u91c7\\u7528<code>-O2<\\/code>\\u7ea7\\u4f18\\u5316\\u3002<a href=\\\"https:\\/\\/github.com\\/google\\/sanitizers\\/wiki\\/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer<\\/a> \\u4e5f\\u88ab\\u5f00\\u542f\\u6765\\u68c0\\u6d4b<code>out-of-bounds<\\/code>\\u548c<code>use-after-free<\\/code>\\u9519\\u8bef\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u4f7f\\u7528\\u65b9\\u4fbf\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8\\u5bfc\\u5165\\u3002<\\/p>\"],\"java\":[\"Java\",\"<p>\\u7248\\u672c\\uff1a<code>OpenJDK 17<\\/code>\\u3002\\u53ef\\u4ee5\\u4f7f\\u7528Java 8\\u7684\\u7279\\u6027\\u4f8b\\u5982\\uff0clambda expressions \\u548c stream API\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u88ab\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5305\\u542b Pair \\u7c7b: https:\\/\\/docs.oracle.com\\/javase\\/8\\/javafx\\/api\\/javafx\\/util\\/Pair.html <\\/p>\"],\"python\":[\"Python\",\"<p>\\u7248\\u672c\\uff1a <code>Python 2.7.12<\\/code><\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u5e38\\u7528\\u5e93\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8 \\u5bfc\\u5165\\uff0c\\u5982\\uff1a<a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/array.html\\\" target=\\\"_blank\\\">array<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/bisect.html\\\" target=\\\"_blank\\\">bisect<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/collections.html\\\" target=\\\"_blank\\\">collections<\\/a>\\u3002\\u5982\\u679c\\u60a8\\u9700\\u8981\\u4f7f\\u7528\\u5176\\u4ed6\\u5e93\\u51fd\\u6570\\uff0c\\u8bf7\\u81ea\\u884c\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u6ce8\\u610f Python 2.7 <a href=\\\"https:\\/\\/www.python.org\\/dev\\/peps\\/pep-0373\\/\\\" target=\\\"_blank\\\">\\u5c06\\u57282020\\u5e74\\u540e\\u4e0d\\u518d\\u7ef4\\u62a4<\\/a>\\u3002 \\u5982\\u60f3\\u4f7f\\u7528\\u6700\\u65b0\\u7248\\u7684Python\\uff0c\\u8bf7\\u9009\\u62e9Python 3\\u3002<\\/p>\"],\"c\":[\"C\",\"<p>\\u7248\\u672c\\uff1a<code>GCC 8.2<\\/code>\\uff0c\\u91c7\\u7528GNU99\\u6807\\u51c6\\u3002<\\/p>\\r\\n\\r\\n<p>\\u7f16\\u8bd1\\u65f6\\uff0c\\u5c06\\u4f1a\\u91c7\\u7528<code>-O1<\\/code>\\u7ea7\\u4f18\\u5316\\u3002 <a href=\\\"https:\\/\\/github.com\\/google\\/sanitizers\\/wiki\\/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer<\\/a>\\u4e5f\\u88ab\\u5f00\\u542f\\u6765\\u68c0\\u6d4b<code>out-of-bounds<\\/code>\\u548c<code>use-after-free<\\/code>\\u9519\\u8bef\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u4f7f\\u7528\\u65b9\\u4fbf\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5982\\u60f3\\u4f7f\\u7528\\u54c8\\u5e0c\\u8868\\u8fd0\\u7b97, \\u60a8\\u53ef\\u4ee5\\u4f7f\\u7528 <a href=\\\"https:\\/\\/troydhanson.github.io\\/uthash\\/\\\" target=\\\"_blank\\\">uthash<\\/a>\\u3002 \\\"uthash.h\\\"\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5bfc\\u5165\\u3002\\u8bf7\\u770b\\u5982\\u4e0b\\u793a\\u4f8b:<\\/p>\\r\\n\\r\\n<p><b>1. \\u5f80\\u54c8\\u5e0c\\u8868\\u4e2d\\u6dfb\\u52a0\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n<pre>\\r\\nstruct hash_entry {\\r\\n int id; \\/* we'll use this field as the key *\\/\\r\\n char name[10];\\r\\n UT_hash_handle hh; \\/* makes this structure hashable *\\/\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n<\\/pre>\\r\\n<\\/p>\\r\\n\\r\\n<p><b>2. \\u5728\\u54c8\\u5e0c\\u8868\\u4e2d\\u67e5\\u627e\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n<pre>\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n struct hash_entry *s;\\r\\n HASH_FIND_INT(users, &user_id, s);\\r\\n return s;\\r\\n}\\r\\n<\\/pre>\\r\\n<\\/p>\\r\\n\\r\\n<p><b>3. \\u4ece\\u54c8\\u5e0c\\u8868\\u4e2d\\u5220\\u9664\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n<pre>\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n HASH_DEL(users, user); \\r\\n}\\r\\n<\\/pre>\\r\\n<\\/p>\"],\"csharp\":[\"C#\",\"<p><a href=\\\"https:\\/\\/docs.microsoft.com\\/en-us\\/dotnet\\/csharp\\/whats-new\\/csharp-9\\\" target=\\\"_blank\\\">C# 10<\\/a> \\u8fd0\\u884c\\u5728 .NET 6 \\u4e0a<\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u7f16\\u8bd1\\u65f6\\u9ed8\\u8ba4\\u5f00\\u542f\\u4e86debug\\u6807\\u8bb0(<code>\\/debug:pdbonly<\\/code>)\\u3002<\\/p>\"],\"javascript\":[\"JavaScript\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\\" target=\\\"_blank\\\"> datastructures-js\\/queue<\\/a>\\u3002<\\/p>\"],\"ruby\":[\"Ruby\",\"<p>\\u4f7f\\u7528<code>Ruby 3.1<\\/code>\\u6267\\u884c<\\/p>\\r\\n\\r\\n<p>\\u4e00\\u4e9b\\u5e38\\u7528\\u7684\\u6570\\u636e\\u7ed3\\u6784\\u5df2\\u5728 Algorithms \\u6a21\\u5757\\u4e2d\\u63d0\\u4f9b\\uff1ahttps:\\/\\/www.rubydoc.info\\/github\\/kanwei\\/algorithms\\/Algorithms<\\/p>\"],\"swift\":[\"Swift\",\"<p>\\u7248\\u672c\\uff1a<code>Swift 5.5.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u6211\\u4eec\\u901a\\u5e38\\u4fdd\\u8bc1\\u66f4\\u65b0\\u5230 <a href=\\\"https:\\/\\/swift.org\\/download\\/\\\" target=\\\"_blank\\\">Apple\\u653e\\u51fa\\u7684\\u6700\\u65b0\\u7248Swift<\\/a>\\u3002\\u5982\\u679c\\u60a8\\u53d1\\u73b0Swift\\u4e0d\\u662f\\u6700\\u65b0\\u7248\\u7684\\uff0c\\u8bf7\\u8054\\u7cfb\\u6211\\u4eec\\uff01\\u6211\\u4eec\\u5c06\\u5c3d\\u5feb\\u66f4\\u65b0\\u3002<\\/p>\"],\"golang\":[\"Go\",\"<p>\\u7248\\u672c\\uff1a<code>Go 1.17<\\/code><\\/p>\\r\\n\\r\\n<p>\\u652f\\u6301 <a href=\\\"https:\\/\\/godoc.org\\/github.com\\/emirpasic\\/gods\\\" target=\\\"_blank\\\">https:\\/\\/godoc.org\\/github.com\\/emirpasic\\/gods<\\/a> \\u7b2c\\u4e09\\u65b9\\u5e93\\u3002<\\/p>\"],\"python3\":[\"Python3\",\"<p>\\u7248\\u672c\\uff1a<code>Python 3.10<\\/code><\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u5e38\\u7528\\u5e93\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8 \\u5bfc\\u5165\\uff0c\\u5982<a href=\\\"https:\\/\\/docs.python.org\\/3\\/library\\/array.html\\\" target=\\\"_blank\\\">array<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/3\\/library\\/bisect.html\\\" target=\\\"_blank\\\">bisect<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/3\\/library\\/collections.html\\\" target=\\\"_blank\\\">collections<\\/a>\\u3002 \\u5982\\u679c\\u60a8\\u9700\\u8981\\u4f7f\\u7528\\u5176\\u4ed6\\u5e93\\u51fd\\u6570\\uff0c\\u8bf7\\u81ea\\u884c\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5982\\u9700\\u4f7f\\u7528 Map\\/TreeMap \\u6570\\u636e\\u7ed3\\u6784\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"http:\\/\\/www.grantjenks.com\\/docs\\/sortedcontainers\\/\\\" target=\\\"_blank\\\">sortedcontainers<\\/a> \\u5e93\\u3002<\\/p>\"],\"scala\":[\"Scala\",\"<p>\\u7248\\u672c\\uff1a<code>Scala 2.13<\\/code><\\/p>\"],\"kotlin\":[\"Kotlin\",\"<p>\\u7248\\u672c\\uff1a<code>Kotlin 1.3.10<\\/code><\\/p>\"],\"rust\":[\"Rust\",\"<p>\\u7248\\u672c\\uff1a<code>rust 1.58.1<\\/code><\\/p>\\r\\n\\r\\n<p>\\u652f\\u6301 crates.io \\u7684 <a href=\\\"https:\\/\\/crates.io\\/crates\\/rand\\\" target=\\\"_blank\\\">rand<\\/a><\\/p>\"],\"php\":[\"PHP\",\"<p><code>PHP 8.1<\\/code>.<\\/p>\\r\\n\\r\\n<p>With bcmath module.<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 4.5.4<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2020<\\/p>\"],\"racket\":[\"Racket\",\"<p><a href=\\\"https:\\/\\/docs.racket-lang.org\\/guide\\/performance.html#%28tech._c%29\\\" target=\\\"_blank\\\">Racket CS<\\/a> v8.3<\\/p>\\r\\n\\r\\n<p>\\u4f7f\\u7528 #lang racket<\\/p>\\r\\n\\r\\n<p>\\u5df2\\u9884\\u5148 (require data\\/gvector data\\/queue data\\/order data\\/heap). \\u82e5\\u9700\\u4f7f\\u7528\\u5176\\u5b83\\u6570\\u636e\\u7ed3\\u6784\\uff0c\\u53ef\\u81ea\\u884c require\\u3002<\\/p>\"],\"erlang\":[\"Erlang\",\"Erlang\\/OTP 24.2\"],\"elixir\":[\"Elixir\",\"Elixir 1.13.0 with Erlang\\/OTP 24.2\"]}",
|
||
"book": null,
|
||
"isSubscribed": false,
|
||
"isDailyQuestion": false,
|
||
"dailyRecordStatus": null,
|
||
"editorType": "CKEDITOR",
|
||
"ugcQuestionId": null,
|
||
"style": "LEETCODE",
|
||
"exampleTestcases": "[\"Encrypter\",\"encrypt\",\"decrypt\"]\n[[[\"a\",\"b\",\"c\",\"d\"],[\"ei\",\"zf\",\"ei\",\"am\"],[\"abcd\",\"acbd\",\"adbc\",\"badc\",\"dacb\",\"cadb\",\"cbda\",\"abad\"]],[\"abcd\"],[\"eizfeiam\"]]",
|
||
"__typename": "QuestionNode"
|
||
}
|
||
}
|
||
} |