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