Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- 캐치카페
- Docker
- 백준
- SW Expert Academy
- 맥북
- leetcode
- 자연어처리
- Git
- github
- 코로나19
- 편스토랑
- hackerrank
- Kaggle
- 파이썬
- Real or Not? NLP with Disaster Tweets
- 금융문자분석경진대회
- ChatGPT
- 편스토랑 우승상품
- programmers
- gs25
- 더현대서울 맛집
- AI 경진대회
- ubuntu
- 데이콘
- dacon
- PYTHON
- 프로그래머스
- 프로그래머스 파이썬
- 우분투
- Baekjoon
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 1189. Maximum Number of Balloons (Python) 본문
Programming/코딩 1일 1문제
[leetCode] 1189. Maximum Number of Balloons (Python)
솜씨좋은장씨 2020. 9. 20. 00:33728x90
반응형
Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible.
You can use each character in text at most once. Return the maximum number of instances that can be formed.
Example 1:
Input: text = "nlaebolko"
Output: 1
Example 2:
Input: text = "loonbalxballpoon"
Output: 2
Example 3:
Input: text = "leetcode"
Output: 0
Constraints:
- 1 <= text.length <= 10^4
- text consists of lower case English letters only.
Solution
from collections import Counter
class Solution:
def maxNumberOfBalloons(self, text: str) -> int:
cnt = collections.Counter(text)
ballon_key = ["b", "a", "l", "o", "n"]
for key in ballon_key:
if key not in list(cnt.keys()):
return 0
return min(cnt['b'],cnt['a'],cnt['l']//2,cnt['o']//2,cnt['n'])
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 657. Robot Return to Origin (Python) (0) | 2020.09.22 |
---|---|
[leetCode] 703. Kth Largest Element in a Stream (Python) (0) | 2020.09.21 |
[leetCode] 645. Set Mismatch (Python) (0) | 2020.09.19 |
[leetCode] 191. Number of 1 Bits (Python) (0) | 2020.09.18 |
[leetCode] 705. Design HashSet (Python) (0) | 2020.09.17 |
Comments