C++ C Py3 Rust數bits解Leetcode 2749 Minimum Operations to Make the Integer Zero
[Py3解請進]
解Leetcode 2749. Minimum Operations to Make the Integer Zero。就程式而言,並不困難,難就在當num2為負數時如何去評估可能的上界,這真需要複雜度分析,利用成長曲線的特定,可以確定不會無上界,而導致無窮迴圈,但精確的上界就很難。
------
From a programming perspective, it's not difficult. The difficulty lies in how to evaluate the possible upper bound when num2 is negative. This really requires complexity analysis. By using the specificity of the growth curve, we can ensure that there cannot be no upper bound, which will lead to an infinite loop, but an exact upper bound is difficult to determine.
[codes on leetcode]https://leetcode.com/problems/minimum-operations-to-make-the-integer-zero/solutions/7156781/count-bits-c-c-py3-rust-beats-100/
[bit/ bitmask playlist]https://www.youtube.com/watch?v=Hw1fnQA8Nk8&list=PLYRlUBnWnd5K8FlzJ6tOswqQcsk7R1Duh
class Solution: def makeTheIntegerZero(self, num1: int, num2: int) -> int: x, k=num1, 1 while True: x-=num2 if x<k: return -1 if k>=x.bit_count(): return k k+=1 return -1
沒有留言:
張貼留言