<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                In a deck of cards, each card has an integer written on it. Return`true`if and only if you can choose?`X >= 2`such that?it is possible to split the entire deck?into 1 or more groups of cards, where: * Each group has exactly`X`cards. * All the cards in each group have the same integer. **Example 1:** ~~~ Input: [1,2,3,4,4,3,2,1] Output: true Explanation: Possible partition [1,1],[2,2],[3,3],[4,4] ~~~ **Example 2:** ~~~ Input: [1,1,1,2,2,2,3,3] Output: false Explanation: No possible partition. ~~~ **Example 3:** ~~~ Input: [1] Output: false Explanation: No possible partition. ~~~ **Example 4:** ~~~ Input: [1,1] Output: true Explanation: Possible partition [1,1] ~~~ **Example 5:** ~~~ Input: [1,1,2,2,2,2] Output: true Explanation: Possible partition [1,1],[2,2],[2,2] ~~~ **Note:** 1. `1 <= deck.length <= 10000` 2. `0 <= deck[i] <?10000` ``` var hasGroupsSizeX = function(deck) { // 最大公約數計算公式 function gcd(num1, num2) { // 利用輾轉相除法來計算最大公約數 return num2 === 0 ? num1 : gcd(num2, num1 % num2); } // 相同牌出現次數Map let timeMap = new Map(); // 遍歷牌 deck.forEach(num => { // 統計每張牌出現的次數 timeMap.set(num, timeMap.has(num) ? timeMap.get(num) + 1 : 1); }); // Map.protype.values()返回的是一個新的Iterator對象, 所以可以使用擴展運算符(...)來構造成數組 let timeAry = [...timeMap.values()]; /* 最大公約數 因為該數組是出現次數數組,最小值至少為1(至少出現1次), 所以默認賦值為數組首位對公約數計算無干擾 */ let g = timeAry[0]; // 遍歷出現次數,計算最大公約數 timeAry.forEach(time => { // 因為需要比較所有牌出現次數的最大公約數,故需要一個中間值 g = gcd(g, time); }); // 判斷是否滿足題意 return g >= 2; }; ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看