当前位置: 首页> 汽车> 行情 > 私域流量运营平台有哪些_太原网站建设推广服务_百度移动开放平台_seo上海公司

私域流量运营平台有哪些_太原网站建设推广服务_百度移动开放平台_seo上海公司

时间:2025/7/21 7:47:29来源:https://blog.csdn.net/u013302570/article/details/145204917 浏览次数: 0次
私域流量运营平台有哪些_太原网站建设推广服务_百度移动开放平台_seo上海公司

3095. 或值至少 K 的最短子数组 I

3097. Shortest Subarray With OR at Least K II

class Solution:def minimumSubarrayLength(self, nums: List[int], k: int) -> int:n = len(nums)bits = [0] * 30res = infdef calc(bits):return sum(1 << i for i in range(30) if bits[i] > 0)left = 0for right in range(n):for i in range(30):bits[i] += (nums[right] >> i) & 1while left <= right and calc(bits) >= k:res = min(res, right - left + 1)for i in range(30):bits[i] -= (nums[left] >> i) & 1left += 1return -1 if res == inf else res

2595. Number of Even and Odd Bits

class Solution:def evenOddBit(self, n: int) -> List[int]:res = [0, 0]i = 0while n:res[i] += n & 1n >>= 1i = i ^ 1return res
  • n >>= 1: Performs a right bitwise shift on n
  • i = i ^ 1: This cleverly toggles the index i between 0 and 1. The ^ operator is the bitwise XOR. Since i is either 0 or 1:
    If i is 0, 0 ^ 1 is 1.
    If i is 1, 1 ^ 1 is 0.
Binary representation of 8: 1000
Iterations:
Iteration 1:
n = 8 (1000)
n & 1 = 1000 & 0001 = 0000 = 0
res[0] = 0 + 0 = 0
n >>= 1 (n becomes 4, which is 0100)
i = 0 ^ 1 = 1Iteration 2:
n = 4 (0100)
n & 1 = 0100 & 0001 = 0000 = 0
res[1] = 0 + 0 = 0
n >>= 1 (n becomes 2, which is 0010)
i = 1 ^ 1 = 0Iteration 3:
n = 2 (0010)
n & 1 = 0010 & 0001 = 0000 = 0
res[0] = 0 + 0 = 0
n >>= 1 (n becomes 1, which is 0001)
i = 0 ^ 1 = 1Iteration 4:
n = 1 (0001)
n & 1 = 0001 & 0001 = 0001 = 1
res[1] = 0 + 1 = 1
n >>= 1 (n becomes 0, which is 0000)
i = 1 ^ 1 = 0
Loop terminates because n is now 0.Return value:
res = [0, 1]
关键字:私域流量运营平台有哪些_太原网站建设推广服务_百度移动开放平台_seo上海公司

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: