日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

LeetCode 819. Most Common Word

發布時間:2025/5/22 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LeetCode 819. Most Common Word 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原題鏈接在這里:https://leetcode.com/problems/most-common-word/description/

題目:

Given a paragraph?and a list of banned words, return the most frequent word that is not in the list of banned words.? It is guaranteed there is at least one word that isn't banned, and that the answer is unique.

Words in the list of banned words are given in lowercase, and free of punctuation.? Words in the paragraph are not case sensitive.? The answer is in lowercase.

Example: Input: paragraph = "Bob hit a ball, the hit BALL flew far after it was hit." banned = ["hit"] Output: "ball" Explanation: "hit" occurs 3 times, but it is a banned word. "ball" occurs twice (and no other word does), so it is the most frequent non-banned word in the paragraph. Note that words in the paragraph are not case sensitive, that punctuation is ignored (even if adjacent to words, such as "ball,"), and that "hit" isn't the answer even though it occurs more because it is banned.

Note:

  • 1 <= paragraph.length <= 1000.
  • 1 <= banned.length <= 100.
  • 1 <= banned[i].length <= 10.
  • The answer is unique, and written in lowercase (even if its occurrences in?paragraph?may have?uppercase symbols, and even if it is a proper noun.)
  • paragraph?only consists of letters, spaces, or the punctuation symbols?!?',;.
  • Different words in?paragraph?are always separated by a space.
  • There are no hyphens or hyphenated words.
  • Words only consist of letters, never apostrophes or other punctuation symbols

題解:

遇到不是letter的char就把當前采集到的詞頻率加一. 如果高于目前最大頻率就更換res.

Note: paragraph 本身末位加個符號. 否則會丟掉最后一個詞.

Time Complexity: O(m+n). m = paragraph.length(). n = banned.length.

Space: O(m+n).

AC Java:

1 class Solution { 2 public String mostCommonWord(String paragraph, String[] banned) { 3 HashSet<String> hs = new HashSet<String>(Arrays.asList(banned)); 4 paragraph += '.'; 5 6 String res = ""; 7 int count = 0; 8 HashMap<String, Integer> hm = new HashMap<String, Integer>(); 9 10 StringBuilder sb = new StringBuilder(); 11 for(char c : paragraph.toCharArray()){ 12 if(Character.isLetter(c)){ 13 sb.append(Character.toLowerCase(c)); 14 }else if(sb.length() > 0){ 15 String s = sb.toString(); 16 if(!hs.contains(s)){ 17 hm.put(s, hm.getOrDefault(s, 0)+1); 18 if(hm.get(s) > count){ 19 res = s; 20 count = hm.get(s); 21 } 22 } 23 24 sb = new StringBuilder(); 25 } 26 } 27 28 return res; 29 } 30 }

?

轉載于:https://www.cnblogs.com/Dylan-Java-NYC/p/9771565.html

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的LeetCode 819. Most Common Word的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 免费国产高清 | 亚洲高清在线视频 | 国产精品视频看看 | 亚洲AV无码成人精品国产一区 | 天天干天天爱天天射 | 久久久精品人妻一区二区三区色秀 | 欧美激情喷水 | 象人高潮调教丨vk | 麻豆av片| 国产精品乱码妇女bbbb | 午夜精品久久久久久久蜜桃 | 欧美午夜精品久久久久久浪潮 | 富二代成人短视频 | 亚欧美视频 | 中文字幕一区二区三区精华液 | 国产精品黄色在线观看 | 久热精品在线观看视频 | 波多野结衣人妻 | 亚洲欧美在线视频观看 | 男女午夜影院 | 免费av的网站 | 国产成人无码精品 | 亚洲黄色大片 | 99这里只有精品视频 | 亚洲人屁股眼子交1 | 伊人久久综合影院 | xxxxwwww在线观看| 亚洲国产精品无码专区 | 黄色三级网站在线观看 | 嫩草影院一区二区 | 男女视频免费观看 | 欧美亚洲另类在线 | 国产高清一 | 亚洲美女在线观看 | 日韩欧美a级片 | 少妇极品熟妇人妻无码 | 欧美日韩国产亚洲沙发 | 色中文字幕 | 无套中出丰满人妻无码 | 天堂欧美 | 欧美夫妻性生活视频 | 国产精品国产三级国产aⅴ中文 | 国产又粗又黄视频 | xxxxhd欧美| 国产精品久久毛片av大全日韩 | 最新国产三级 | www.-级毛片线天内射视视 | 婷婷调教口舌奴ⅴk | 久久久久亚洲色欲AV无码网站 | 大胸喷奶水www视频妖精网站 | 日韩精品在线观看AV | 奇米四色影视 | 国产亚洲av在线 | 男女无遮挡做爰猛烈视频 | 欧美日韩精品在线播放 | 521av在线 | 久久新网址 | 毛片123 | 久久久这里有精品 | 最新国产在线视频 | 日日不卡av | 99热99re6国产在线播放 | 老熟女高潮一区二区三区 | 97人妻精品一区二区三区免 | 日韩网站在线观看 | 国产精品剧情一区 | 久久在线免费观看视频 | 中文字幕在线观看1 | 韩国av网| 91日韩精品| 日韩在线中文字幕视频 | 91成人在线视频 | 桃谷绘里香番号 | 国产老头户外野战xxxxx | 少妇粉嫩小泬白浆流出 | 国产精品中文字幕在线观看 | 国产中年熟女高潮大集合 | 色眯眯视频| 91呦呦| 天天爽天天色 | 久久亚洲综合网 | 国内精品亚洲 | 18pao国产成视频永久免费 | 国产在线综合网 | 日本精品99 | 国产盗摄av | 欧美在线亚洲 | 麻豆精品一区 | 欧美日韩国产片 | 综合精品一区 | 深夜福利视频网站 | 国产免费一区二区三区免费视频 | av加勒比在线 | 91在线中文字幕 | 中文字幕乱视频 | 成人午夜精品福利免费 | 日韩国产在线观看 | 免费黄网站在线 | 欧美日韩免费高清一区色橹橹 |