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
- 캐치카페
- 백준
- Real or Not? NLP with Disaster Tweets
- 프로그래머스
- 편스토랑
- 데이콘
- SW Expert Academy
- Baekjoon
- hackerrank
- gs25
- 프로그래머스 파이썬
- 금융문자분석경진대회
- programmers
- AI 경진대회
- Docker
- 더현대서울 맛집
- ChatGPT
- 자연어처리
- 파이썬
- ubuntu
- Kaggle
- 우분투
- leetcode
- 맥북
- dacon
- PYTHON
- 코로나19
- github
- 편스토랑 우승상품
- Git
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'])



SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'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 |