加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

[Swift]LeetCode1189.

发布时间:2020-12-14 04:26:14 所属栏目:百科 来源:网络整理
导读:★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ?微信公众号:为敢(WeiGanTechnologies) ?博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/) ?GitHub地址:https://github.com/strengthen/LeetCode ?原文

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
?微信公众号:为敢(WeiGanTechnologies)
?博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)
?GitHub地址:https://github.com/strengthen/LeetCode
?原文地址:https://www.cnblogs.com/strengthen/p/11521665.html
?如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
?原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

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.

给你一个字符串?text,你需要使用?text?中的字母来拼凑尽可能多的单词?"balloon"(气球)。

字符串?text?中的每个字母最多只能被使用一次。请你返回最多可以拼凑出多少个单词?"balloon"。

?

示例 1:

输入:text = "nlaebolko"
输出:1

示例 2:

输入:text = "loonbalxballpoon"
输出:2

示例 3:

输入:text = "leetcode"
输出:0

?

提示:

  • 1 <= text.length <= 10^4
  • text?全部由小写英文字母组成

Runtime:?16 ms
Memory Usage:?20.7 MB
 1 class Solution {
 2     func maxNumberOfBalloons(_ text: String) -> Int {
 3         var F:[Character:Int] = [Character:Int]()
 4         for c in text
 5         {
 6             F[c,default:0] += 1
 7         }
 8         return min(F["b",default:0],F["a",F["l",default:0]/2,F["o",F["n",default:0])
 9     }
10 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读