1/**2* @param {number} target3* @return {number}4*/5var racecar = function (target) {6const queue = [{ position: 0, speed: 1, sequence: "" }];78while (queue.length) {9let { position, speed, sequence } = queue.shift();1011if (position === target) return sequence.length;1213const newPosition = position + speed;1415queue.push({16position: newPosition,17speed: speed * 2,18sequence: sequence + "A",19});2021if (22(newPosition > target && speed > 0) ||23(newPosition < target && speed < 0)24) {25queue.push({26sequence: sequence + "R",27position,28speed: Math.sign(speed) === 1 ? -1 : 1,29});30}31}3233return 0;34};