程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Leetcode[1189] maximum number of balloons python3 implementation (counter two lines of code)

編輯:Python
# Give you a string text, You need to use text To piece together as many words as possible "balloon"( balloon ). 
# 
# character string text Each letter in can only be used once at most . Please return the maximum number of words you can piece together "balloon". 
# 
# 
# 
# Example 1: 
# 
# 
# 
# Input :text = "nlaebolko"
# Output :1
# 
# 
# Example 2: 
# 
# 
# 
# Input :text = "loonbalxballpoon"
# Output :2
# 
# 
# Example 3: 
# 
# Input :text = "leetcode"
# Output :0
# 
# 
# 
# 
# Tips : 
# 
# 
# 1 <= text.length <= 10^4 
# text All consist of lowercase English letters 
# 
# Related Topics Hashtable character string Count 68 0
# leetcode submit region begin(Prohibit modification and deletion)
class Solution:
def maxNumberOfBalloons(self, text: str) -> int:
cnt = Counter(text)
return min(cnt['b'], cnt['a'], cnt['l']//2, cnt['o']//2, cnt['n'])
# leetcode submit region end(Prohibit modification and deletion)

use counter Two lines .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved