Created
August 20, 2022 15:13
-
-
Save Ray-Eldath/9509ea039be579adc8e3f41016efb9e7 to your computer and use it in GitHub Desktop.
Leetcode Helper: 力扣刷题常用辅助功能
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ltarreq 用于判断两组数组字符串是否相等。返回每组的判等情况。 | |
// 力扣中有许多「不限返回顺序」的题目(如 #401 二进制手表、#77 组合、#47 全排列,等等), | |
// 若你的答案的顺序和预期结果的顺序不一致,一行行、一项项比较会非常累人。 | |
// 这时,将整个多行的「输出」和多行的「预期结果」用反引号(`)包住传入该方法,即可自动比较它们的相等性。 | |
// | |
// TODO: 等我闲下来会将这个功能做成油猴脚本 / 浏览器插件,如果我在刷题中还发现了什么需要的功能会继续更新本 gist。 | |
function ltarreq(a, b) { | |
as = a.split("\n") | |
bs = b.split("\n") | |
if (as.length != bs.length) return false | |
res = [] | |
for (let i = 0; i < as.length; i++) | |
res.push(JSON.stringify(JSON.parse(as[i]).sort()) === JSON.stringify(JSON.parse(bs[i]).sort())) | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment