-
github.com/onlybooks/algorithm-interview
역시 코딩은 잘되면 너무 재밌어 🤣
819. Most Common Word
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.
Most Common Word - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
onlybooks/algorithm-interview
<파이썬 알고리즘 인터뷰> 95가지 알고리즘 문제 풀이로 완성하는 코딩 테스트. Contribute to onlybooks/algorithm-interview development by creating an account on GitHub.
github.com
저번에도 봤듯이, 문자만 취하려면 정규식을 이용할 수 있다.
[파이썬 알고리즘 인터뷰] 유효한 팰린드롬
팰린드롬 앞뒤가 똑같은 문장이나 단어 "소주 만 병만 주소" 😂😂😂😂😂😂 isalnum(): 영문자, 숫자 여부를 판단 사용하면 아래와 같이 특수문자를 제외한 나머지 영문,한글 숫자만을 체크할
weejw.tistory.com
1157번: 단어 공부
알파벳 대소문자로 된 단어가 주어지면, 이 단어에서 가장 많이 사용된 알파벳이 무엇인지 알아내는 프로그램을 작성하시오. 단, 대문자와 소문자를 구분하지 않는다.
www.acmicpc.net
from collections import Counter res = Counter(input().upper()).most_common(2) if len(res)==1 or (len(res)==2 and res[0][1] != res[1][1]): print(res[0][0]) else: print("?")
'2020년 > 코테' 카테고리의 다른 글
[파이썬 알고리즘 인터뷰] 가장 킨 팰린드롬 (0) 2020.12.19 [파이썬 알고리즘 인터뷰] 그룹 애너그램 (0) 2020.12.19 [파이썬 알고리즘 인터뷰] 로그파일 재정렬 (0) 2020.12.19 [파이썬 알고리즘 인터뷰] 문자열 뒤집기 (0) 2020.12.15 [파이썬 알고리즘 인터뷰] 유효한 팰린드롬 (0) 2020.12.13