我比较笨,不会写什么高级的算法,所以按照题目的描述,翻译成了代码。不知道我写的有没有问题。 function cowSize(n) { let cows = [0]; for (let year = 0; year < n; year++) { for (let index = 0, count = cows.length; index < count; index++) { cows[index] += 1; if (cows[index] >= 3) { cows.push(0); } } } return cows.length; }