<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                >[success] # 刷題前知識補充 在做字母字符問題時候可以利用**ASCII** 對應的字符集作為數組腳標,用來記錄出現次數,例如英文小寫單詞**a-z**,所對應的字符集**97-122**,舉個例子現在要記錄`azsxzxxs` 中每個字符出現 1. 先創建一個26長度數組 2. 將字符轉換對應ascii碼,記錄到對應數組位置 ~~~ // 只會有小寫字母 const w = 'azsxzxxs' function getWordCounts(words) { // 創建一個26 長度數組 const ls = new Array(26).fill(0) // 因為小寫a 是從97開始 const ascii_a = 'a'.charCodeAt() // 循環每個單詞找到對應的ascii碼記錄保存 for (let i = 0; i < words.length; i++) { // charCodeAt 參數是當前字符所應轉換為ascii,減掉97 const idx = words.charCodeAt(i) - ascii_a ls[idx]++ } // 打印每個字符出現此時 return ls.reduce((acc, cur, index) => { // 轉換將ascii 碼對應碼轉換為對應小寫單詞 if (cur) { const w = String.fromCharCode(index + ascii_a) acc[w] = cur } return acc }, {}) } console.log(getWordCounts(w)) // { a: 1, s: 2, x: 3, z: 2 } ~~~ * 利用Map 映射來做 ~~~ // 只會有小寫字母 const w = 'azsxzxxs' function getWordCounts(words) { const obj = {} for (let w of words) { if (!obj[w]) obj[w] = 0 obj[w]++ } return obj } console.log(getWordCounts(w)) ~~~
                  <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>

                              哎呀哎呀视频在线观看