/* 自定義代碼塊樣式 */

herrDeng網內搜尋

自訂搜尋

Ads

2026年6月22日 星期一

0ms|Leetcode1189 text中可有幾個ballon|C++ 1 liner Py3


0ms|Leetcode1189 text中可有幾個ballon|C++ 1 linerPy3 
會處理count freq,接著來就能處理counting sort
[Leetcode 1833 Maximum Ice Cream Bars|Greedy counting sort]https://www.youtube.com/watch?v=4deOmcdAekg
[Py3 1-liner請進]


timestamps for the key sections:
00:00 - Introduction to LeetCode 1189 and the "balloon" counting problem.
00:19 - Code submission and performance result (0ms).
00:28 - C++ implementation details: frequency array and character counting.
00:54 - Explanation of the bitwise shift (right shift) for division by 2.
01:02 - Python implementation: 1-liner solution using collections.Counter.
01:44 - Final Python code submission and 0ms result.
class Solution:
    def maxNumberOfBalloons(self, text: str) -> int:
        return min((f:=Counter(text))['a'], f['b'], f['l']//2, f['o']//2, f['n'] )

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章