題目:請實作一個函式用來找出字符流中第一個只出現一次的字符,例如,當從字符流中只讀出前兩個字符"go"時,第一個只出現一次的字符是"g",當從該字符流中讀出前六個字符“google"時,第一個只出現一次的字符是"l",
輸出描述:如果當前字符流沒有存在出現一次的字符,回傳#字符,
用harsh表統計次數:
let map={} function init(){ map={} } function Insert(ch){ if(map[ch]){ map[ch]+=1 }else{ map[ch]=1 } } function FirstAppearingOnce(){ for(const i in map){ if(map[i]===1){ return i } } return ‘#’ }
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/27620.html
標籤:其他
上一篇:字串----表示字符的字串
下一篇:程式員跳槽時關于薪水的那點事
