给定一个键和一个字符串数组,请对该数组进行混洗,以便在每个元素与该键进行XOR运算时将其排序。
对两个字符串进行异或
要通过键对字符串进行异或,请将该键对中的每个字符值通过键中的对进行异或,以使该键永远重复。例如,abcde^123
如下所示:
a b c d e
1 2 3 1 2
--------------------------------------------
01100001 01100010 01100011 01100100 01100101
00110001 00110010 00110011 00110001 00110010
--------------------------------------------
01010000 01010000 01010000 01010101 01010111
--------------------------------------------
P P P U W
排序
排序应始终按XOR字符串的顺序进行。也就是说,1 < A < a < ~
(假设ASCII编码)
例
"912", ["abcde", "hello", "test", "honk"]
-- XOR'd
["XSQ]T", "QT^U^", "MTAM", "Q^\R"]
-- Sorted
["MTAM", "QT^U^", "Q^\R", "XSQ]T"]
-- Converted back
["test", "hello", "honk", "abcde"]
笔记
测试用例
key, input -> output
--------------------
"912", ["abcde", "hello", "test", "honk"] -> ["test", "hello", "honk", "abcde"]
"taco", ["this", "is", "a", "taco", "test"] -> ["taco", "test", "this", "a", "is"]
"thisisalongkey", ["who", "what", "when"] -> ["who", "what", "when"]
"3", ["who", "what", "when"] -> ["what", "when", "who"]
这是代码高尔夫球,因此最少字节获胜!