From 9ec6d920a04a217738a32cbf0dad1cac80f208fd Mon Sep 17 00:00:00 2001 From: JJ <167052465+jaredmccarthy@users.noreply.github.com> Date: Thu, 4 Sep 2025 22:06:19 -0600 Subject: [PATCH 1/6] Create 2749.Minimun-Operations-to-make-the-integer-Zero-PYTHON Leetcode problem using python --- ...n-Operations-to-make-the-integer-Zero-PYTHON | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Greedy/2749.Minimum-Operations-to-Make-the-Integer-Zero/2749.Minimun-Operations-to-make-the-integer-Zero-PYTHON diff --git a/Greedy/2749.Minimum-Operations-to-Make-the-Integer-Zero/2749.Minimun-Operations-to-make-the-integer-Zero-PYTHON b/Greedy/2749.Minimum-Operations-to-Make-the-Integer-Zero/2749.Minimun-Operations-to-make-the-integer-Zero-PYTHON new file mode 100644 index 000000000..820e251bf --- /dev/null +++ b/Greedy/2749.Minimum-Operations-to-Make-the-Integer-Zero/2749.Minimun-Operations-to-make-the-integer-Zero-PYTHON @@ -0,0 +1,17 @@ +class Solution(object): + def makeTheIntegerZero(self,num1,num2): + x = num1 + y = num2 + k = 1 + + while True: + x = x - y + if x < k: + return -1 + + if bin(x).count('1') <= k: + return k + + k = k + 1 + +# I hope this can help anyone whos resolving this huge problem on python ;) From 67bc72b75d8d1157c8bd35f1d6a38434064714fc Mon Sep 17 00:00:00 2001 From: wisdompeak Date: Sun, 7 Sep 2025 16:19:49 -0700 Subject: [PATCH 2/6] Update Readme.md --- Binary_Search/3677.Count-Binary-Palindromic-Numbers/Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Binary_Search/3677.Count-Binary-Palindromic-Numbers/Readme.md b/Binary_Search/3677.Count-Binary-Palindromic-Numbers/Readme.md index b6a8b4f5b..1dbc9d5a4 100644 --- a/Binary_Search/3677.Count-Binary-Palindromic-Numbers/Readme.md +++ b/Binary_Search/3677.Count-Binary-Palindromic-Numbers/Readme.md @@ -2,5 +2,5 @@ 假设n的二进制长度是maxLen,那么对于任何1<=lmx`的情况。 +接下来考虑L=maxLen,且"小于等于n"的二进制回文数。比较简单的处理就是用二分搜值。计算`h=(L+1)/2`,然后"前半段"有下限`mn=1<<(h-1)`,上限是`mx=(1<mx`的情况,所以需要对收敛的解做二次验证。 From 615fbdc529f4d6848f615a99401f6c563ae7847d Mon Sep 17 00:00:00 2001 From: wisdompeak Date: Sun, 7 Sep 2025 16:22:49 -0700 Subject: [PATCH 3/6] Update 3677.Count-Binary-Palindromic-Numbers.cpp From de51403fcdda59a69a5bc8ea37c0dd8ce06acfb0 Mon Sep 17 00:00:00 2001 From: wisdompeak Date: Sun, 7 Sep 2025 16:55:05 -0700 Subject: [PATCH 4/6] Create 3676.Count-Bowl-Subarrays.cpp --- .../3676.Count-Bowl-Subarrays.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Stack/3676.Count-Bowl-Subarrays/3676.Count-Bowl-Subarrays.cpp diff --git a/Stack/3676.Count-Bowl-Subarrays/3676.Count-Bowl-Subarrays.cpp b/Stack/3676.Count-Bowl-Subarrays/3676.Count-Bowl-Subarrays.cpp new file mode 100644 index 000000000..50239989f --- /dev/null +++ b/Stack/3676.Count-Bowl-Subarrays/3676.Count-Bowl-Subarrays.cpp @@ -0,0 +1,28 @@ +class Solution { +public: + long long bowlSubarrays(vector& nums) { + int n = nums.size(); + vectornextGreater(n, -1); + vectorprevGreater(n, -1); + vectorst; + for (int i=0; i=0; i--) { + while (!st.empty() && nums[st.back()]=2) ret++; + if (nextGreater[i]!=-1 && nextGreater[i]-i>=2) ret++; + } + return ret; + } +}; From 99b375c2db6c24149459b0c1d975c2b5309c5eec Mon Sep 17 00:00:00 2001 From: wisdompeak Date: Sun, 7 Sep 2025 16:55:32 -0700 Subject: [PATCH 5/6] Update Readme.md --- Readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Readme.md b/Readme.md index b6c812625..063a42457 100644 --- a/Readme.md +++ b/Readme.md @@ -450,6 +450,7 @@ [2434.Using-a-Robot-to-Print-the-Lexicographically-Smallest-String](https://github.com/wisdompeak/LeetCode/tree/master/Stack/2434.Using-a-Robot-to-Print-the-Lexicographically-Smallest-String) (H-) [2454.Next-Greater-Element-IV](https://github.com/wisdompeak/LeetCode/tree/master/Stack/2454.Next-Greater-Element-IV) (H-) [3113.Find-the-Number-of-Subarrays-Where-Boundary-Elements-Are-Maximum](https://github.com/wisdompeak/LeetCode/tree/master/Stack/3113.Find-the-Number-of-Subarrays-Where-Boundary-Elements-Are-Maximum) (M) +[3676.Count-Bowl-Subarrays](https://github.com/wisdompeak/LeetCode/tree/master/Stack/3676.Count-Bowl-Subarrays) (M+) * ``monotonic stack: other usages`` [084.Largest-Rectangle-in-Histogram](https://github.com/wisdompeak/LeetCode/tree/master/Stack/084.Largest-Rectangle-in-Histogram) (H) [2334.Subarray-With-Elements-Greater-Than-Varying-Threshold](https://github.com/wisdompeak/LeetCode/tree/master/Stack/2334.Subarray-With-Elements-Greater-Than-Varying-Threshold) (M+) From b64842c0b244ed2f7f904556be1528741f4402cc Mon Sep 17 00:00:00 2001 From: wisdompeak Date: Sun, 7 Sep 2025 17:00:11 -0700 Subject: [PATCH 6/6] Create Readme.md --- Stack/3676.Count-Bowl-Subarrays/Readme.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Stack/3676.Count-Bowl-Subarrays/Readme.md diff --git a/Stack/3676.Count-Bowl-Subarrays/Readme.md b/Stack/3676.Count-Bowl-Subarrays/Readme.md new file mode 100644 index 000000000..066f63299 --- /dev/null +++ b/Stack/3676.Count-Bowl-Subarrays/Readme.md @@ -0,0 +1,7 @@ +### 3676.Count-Bowl-Subarrays + +非常有趣的题目。 + +我们很容易想到,对于每个nums[i]考虑其作为一个端点时,另一个端点应该在哪些位置。我们不妨认为nums[i]是左边且较低的端点,那么我们很容易找到对应的next greater element,比如说j,这是下一个可以作为右端点的位置,而这恰恰也是它所对应的唯一的右端点。如果再往右寻找右端点,那么j处在bowl内部就高于了左端点,不符合条件。 + +于是我们就可以得出结论,对于每个nums[i],只有唯一的next greater element可以配对为右边且更高的端点。同理,对于每个nums[i],只有唯一的prev greater element可以配对为左边且更高的端点。这样我们就枚举除了所有的bowl的形状。

AltStyle によって変換されたページ (->オリジナル) /