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
[codes on Leetcode]https://leetcode.com/problems/maximum-number-of-balloons/solutions/8350164/count-freqbeats-100-by-anwendeng-be0r/
[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'] )
沒有留言:
張貼留言