翻转卡片游戏

This commit is contained in:
mol
2023-08-02 14:08:31 +08:00
parent ddf756f53d
commit fd5d738ded
4 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,26 @@
/**
* @param {number[]} fronts
* @param {number[]} backs
* @return {number}
*/
var flipgame = function (fronts, backs) {
const res = []
for (let i = 0; i < fronts.length; i++) {
let target = fronts[i]
const hasSome = fronts.some((t, j) => {
return target === t && target === backs[j]
})
!hasSome && res.push(target)
}
for (let i = 0; i < fronts.length; i++) {
let target = backs[i]
const hasSome = fronts.some((t, j) => {
return target === t && target === backs[j]
})
!hasSome && res.push(target)
}
return res.length > 0 ? Math.min(...res) : 0
};