classSolution:defminimumSubarrayLength(self, nums: List[int], k:int)->int:
n =len(nums)
bits =[0]*30
res = inf
defcalc(bits):returnsum(1<< i for i inrange(30)if bits[i]>0)
left =0for right inrange(n):for i inrange(30):
bits[i]+=(nums[right]>> i)&1while left <= right and calc(bits)>= k:
res =min(res, right - left +1)for i inrange(30):
bits[i]-=(nums[left]>> i)&1
left +=1return-1if res == inf else res
2595. Number of Even and Odd Bits
classSolution:defevenOddBit(self, n:int)-> List[int]:
res =[0,0]
i =0while n:
res[i]+= n &1
n >>=1
i = 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=1
Iteration 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=0
Iteration 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=1
Iteration 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]
论文地址:Efficient Memory Management for Large Language Model Serving with PagedAttention
摘要
大语言模型(LLMs)的高吞吐量服务需要一次对足够多的请求进行批处理。然而,现有系统面临困境,因为每个请求的键值…
1. 类的设计思想 Date 类的设计目的是为了封装和处理日期信息,它提供了对日期的基本操作,如日期加减、日期比较、日期合法性检查等。类中的私有成员 int _year, int _month, int _day 存储了日期的年、月、日。 类的声明和构造
Date 类的声明࿱…